在闪亮的应用程序中显示彼此下方的两个按钮

时间:2018-04-16 10:49:13

标签: r shiny

我有以下Shiny应用程序

UI <- fluidPage(
  mainPanel(
    fluidRow(
      splitLayout(cellWidths = c("80%", "20%"),
                  plotOutput("line_graph"),
                  selectInput("button1", "First", c(1, 5, 10),width = "50"),
                  selectInput("button2", "Button", c(1, 5, 10),width = "50%")
      )
    )
  )
)

Server <- function(input, output) {

  output$line_graph <- renderPlot({
    hist(100)
  })

}
shinyApp(ui = UI, server = Server)

主要目标是我在左侧(80%)和旁边20%的右侧车道上得到一个情节,我希望两个按钮位于彼此之下(宽度相同)。

但上面的代码并没有给我想要的输出。对这里出了什么问题的想法?

2 个答案:

答案 0 :(得分:0)

如何定义这样的布局?

UI <- fluidPage(
  sidebarLayout(
    mainPanel(
      plotOutput("line_graph")
    ),
    sidebarPanel(
      selectInput("button1", "First", c(1, 5, 10), width = "100"),
      selectInput("button2", "Button", c(1, 5, 10), width = "100")
    )
  )
)


另一个选项是使用column,其中第一个参数的总和应为12.在这种情况下,它是10 + 2,即10表示情节,2表示下拉。

UI <- shinyUI(fluidPage(
  fluidRow(
    column(10,
           plotOutput("line_graph")),
    column(2,
           selectInput("button1", "First", c(1, 5, 10), width = "100"),
           selectInput("button2", "Button", c(1, 5, 10), width = "100"))
  )
))

答案 1 :(得分:0)

这是我第一次使用splitLayout,这看起来很奇怪。这样就可以了,但是会出现一个无用的滚动条:

UI <- bootstrapPage(
  mainPanel(
    splitLayout(plotOutput("line_graph"),
                fluidRow(
                  column(width=2),
                  column(width=10,
                         selectInput("button1", "First", c(1, 5, 10), width="50px"),
                         selectInput("button2", "Button", c(1, 5, 10), width="50px")
                  )),
                cellWidths = c("60%", "40%")),
    width=12
  )
)

Server <- function(input, output) {
  output$line_graph <- renderPlot({
    hist(100)
  })
}

shinyApp(ui = UI, server = Server)