如何在一行中创建侧边栏和textInput对象

时间:2016-05-05 14:54:31

标签: user-interface shiny

问题是我想在helpText对象的右侧放置一个sidebarPanel对象。这是我的代码:

    ui <- (fluidPage(
# Application title
fluidRow(
  column(12,
  sidebarPanel(
  titlePanel("Visualization"),
  actionButton("goButton", "Go"),
  actionButton("reset", "Reset"),
  actionButton("pause", "Pause"),
  actionButton("resume", "Resume"),
  textInput("initial", "Initial Value", value = "c(-5, 5, 5)")  ,
  textInput("targ", "Target", value = "c(0, 0, 0)"),
  textInput("func", "Objective Function", value = "x1 ^ 2 + exp(x2 ^ 2) + 5 + x3 ^ 2")
)),
  column(12,helpText('XXX'))
)
))

但是,helpText位于sidebarPanel下方。如何解决此问题并在右侧空白区域创建helpText对象。 感谢。

1 个答案:

答案 0 :(得分:1)

您可以将mainPanel添加到第一列并将helpText放在那里。在下面的示例中,我将列的宽度设置为最大12的8。

mainPanel是宽度为8的列的8/12,sidebarPanel的宽度为同一列的4/12。

还有一个地方可以容纳另一列,最大宽度为4,我在那里放了另一个helpText

这个答案可能有点偏离主题,但问题也是vage:)

library(shiny)

ui <- fluidPage(

  fluidRow(
    column(8, # column width goes from 1 to 12 where 12 is the whole screen

           sidebarPanel( # default 4 / 12 ... in this case 3/4 of 8
             titlePanel("Visualization"),
             actionButton("goButton", "Go"),
             actionButton("reset", "Reset"),
             actionButton("pause", "Pause"),
             actionButton("resume", "Resume"),
             textInput("initial", "Initial Value", value = "c(-5, 5, 5)")  ,
             textInput("targ", "Target", value = "c(0, 0, 0)"),
             textInput("func", "Objective Function", value = "x1 ^ 2 + exp(x2 ^ 2) + 5 + x3 ^ 2")
           ),
           mainPanel( # 8 /12 ... so 3/4 of 8
             helpText('XXX'),
             helpText("width of the mainPanel within the first column"),
             hr()
           )
    ),
    column(4, 
           br(),
           helpText('width of the second column'),
           hr()
    )
  )
)

server <- shinyServer(function(input, output) {

})

shinyApp(ui, server)