我希望能够创建多个页面,每个页面都有一组小部件下拉,单选按钮和绘制地图的空间。 Shiny教程展示了如何创建多个页面
shinyUI(navbarPage("My Application",
tabPanel("Component 1"),
tabPanel("Component 2"),
tabPanel("Component 3")
))
如何在每个页面中添加小部件,例如如何将以下内容添加到组件1?
sidebarLayout(
sidebarPanel(
selectizeInput(
'id', label = "Year", choices = NULL,multiple=FALSE,selected="X2015",
options = list(create = TRUE,placeholder = 'Choose the year')
),
# Make a list of checkboxes
radioButtons("radio", label = h3("Radio buttons"),
choices = list("Choice 1" = 1,
"Choice 2" = 2)
和
mainPanel(
plotOutput("distPlot")
)
答案 0 :(得分:5)
您应该阅读tabPanel
的参考页:http://shiny.rstudio.com/reference/shiny/latest/tabPanel.html
shinyUI(
navbarPage("My Application",
tabPanel(
"Component 1",
sidebarLayout(
sidebarPanel(
selectizeInput(
'id', label="Year", choices=NULL, multiple=F, selected="X2015",
options = list(create = TRUE,placeholder = 'Choose the year')
),
# Make a list of checkboxes
radioButtons("radio", label = h3("Radio buttons"),
choices = list("Choice 1" = 1, "Choice 2" = 2)
)
),
mainPanel( plotOutput("distPlot") )
)
),
tabPanel("Component 2"),
tabPanel("Component 3")
)
)
答案 1 :(得分:1)
您可以执行tabPanel("Component 1", ...)
,用所有sidebarPanel
代码替换点。或者,在服务器端使用renderUI
,
library(shiny)
shinyApp(
shinyUI(
navbarPage("My Application",
tabPanel("Component 1", uiOutput('page1')),
tabPanel("Component 2"),
tabPanel("Component 3")
)
),
shinyServer(function(input, output, session) {
output$page1 <- renderUI({
sidebarLayout(
sidebarPanel(
selectizeInput(
'id', label = "Year", choices = NULL,multiple=FALSE,selected="X2015",
options = list(create = TRUE,placeholder = 'Choose the year')
),
## Make a list of checkboxes
radioButtons("radio", label = h3("Radio buttons"),
choices = list("Choice 1" = 1, "Choice 2" = 2))
),
mainPanel(
plotOutput('distPlot')
)
)
})
output$distPlot <- renderPlot({ plot(1) })
})
)