2017-05-24 124 views

回答

0

基本上用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) 
+1

好的。我一直在使用sidebarPanel而沒有使用sidabarLayout幾次之前,只是無法看到sidebarPanel內sidebarLayout之間或只是本身之間的區別 – Rivka

+0

你可以請分享一些代碼,你只使用sidebarPanel? – dvarelas

+0

如果我在您的示例中取消註釋sidebarLayout,則在輸出中可以看到沒有區別。所以這就是爲什麼我想知道爲什麼我應該使用它。 – Rivka