闪亮:sidebarPanel sidebarLayout 之间的区别

shiny: difference between sidebarPanel sidebarLayout

我一直在想什么时候使用 sidebarLayout 什么时候不使用。我被卡住了,也许这里有人可以向我解释一下。

谢谢。

基本上使用 sidebarLayout 指定页面的布局,这意味着您的页面将一分为二;一个 sidebarPanel 和一个 mainPanel.

sidebarLayout 中,您可以使用 sidebarPanel 指定页面侧面板的外观。简而言之,首先使用 sidebarLayout 然后使用 sidebarPanel.

以下示例摘自 shiny's 文档。它说明了上面所说的内容。如果你想让你的页面看起来像下面的应用程序,你可以使用它。

library(shiny)
# Define UI
ui <- fluidPage(

  # Application title
  titlePanel("Hello Shiny!"),

  sidebarLayout(

    # Sidebar with a slider input
    sidebarPanel(
      sliderInput("obs",
                  "Number of observations:",
                  min = 0,
                  max = 1000,
                  value = 500)
    ),

    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("distPlot")
    )
  )
)

# Server logic
server <- function(input, output) {
  output$distPlot <- renderPlot({
    hist(rnorm(input$obs))
  })
}

# Complete app with UI and server components
shinyApp(ui, server)