【发布时间】:2018-03-09 06:36:56
【问题描述】:
我创建了一个具有多个navbarMenus 和tabPanels 的闪亮应用程序。每个navBarMenu 都有单独的conditionalPanels。当我在下面的代码 sn-p 中添加第二个 navBarMenu 时,conditionalPanel 似乎不适用于 tabPanels,因为所有输入都出现在所有 tabPanels 上。不知道我做错了什么。
ui <- shinyUI(tagList(
shinythemes::themeSelector(),
tags$head(
tags$style(HTML("
.shiny-output-error-validation {
color: green;
}
"))
),
navbarPage(title = "Test App",
navbarMenu("nav bar 1", icon = icon("line-chart"),
"menu 1",
"--------",
tabPanel("Tab1",
tabPanel("panel 1", icon = icon("line-chart"),
pageWithSidebar(
headerPanel(""),
sidebarPanel(tags$head(
tags$style(type="text/css", "select { max-width: 400px; }"),
tags$style(type="text/css", ".span4 { max-width: 400px; }"),
tags$style(type="text/css", ".well { max-width: 400px; }"),
tags$style(type="text/css", '#leftPanel { width:200px; float:left;}')
),
conditionalPanel(condition="input.conditionedPanels==1",
dateRangeInput("daterange1", "Select Date Range:", start = "2017-01-01", end = Sys.Date(), width = "100%")
),
conditionalPanel(condition="input.conditionedPanels==2",
dateRangeInput("daterange2", "Select Date Range:", start = "2017-01-01", end = Sys.Date(), width = "100%"),
selectInput("inputw1", "Select cols:", choices = c("col1","col2","col3"), selected = "col1", multiple = FALSE, width = "100%")
),
conditionalPanel(condition="input.conditionedPanels==3"
)
),
mainPanel(
tabsetPanel(id = "conditionedPanels",
tabPanel("tab 1", value = 1, icon = icon("table"),
br(),
h3("Data Table")
),
tabPanel("tab 2", value=2, icon = icon("line-chart"),
column(width = 5, leafletOutput("map1")
)
),
tabPanel("tab 3", value=3 , icon = icon("table"),
tinyMCE('editor1', 'Click to edit text')
)
)
)
)
)
)
),
navbarMenu("nav bar 2", icon = icon("line-chart"),
"menu 1",
"--------",
tabPanel("Tab1",
tabPanel("panel 2", icon = icon("line-chart"),
pageWithSidebar(
headerPanel(""),
sidebarPanel(tags$head(
tags$style(type="text/css", "select { max-width: 400px; }"),
tags$style(type="text/css", ".span4 { max-width: 400px; }"),
tags$style(type="text/css", ".well { max-width: 400px; }"),
tags$style(type="text/css", '#leftPanel { width:200px; float:left;}')
),
conditionalPanel(condition="input.conditionedPanels==4",
dateRangeInput("daterange3", "Select Date Range:", start = "2014-01-01", end = Sys.Date(), width = "100%")
),
conditionalPanel(condition="input.conditionedPanels==5",
dateRangeInput("daterange4", "Select Date Range:", start = "2014-01-01", end = Sys.Date(), width = "100%"),
selectInput("inputw2", "Select cols:", choices = c("col4","col5","col6"), selected = "col1", multiple = FALSE, width = "100%")
),
conditionalPanel(condition="input.conditionedPanels==6"
)
),
mainPanel(
tabsetPanel(id = "conditionedPanels",
tabPanel("tab 1", value = 4, icon = icon("table"),
br(),
h3("Data Table")
),
tabPanel("tab 2", value=5, icon = icon("line-chart"),
column(width = 5, leafletOutput("map1")
)
),
tabPanel("tab 3", value=6 , icon = icon("table"),
tinyMCE('editor2', 'Click to edit text')
)
)
)
)
)
)
)
)
)
)
server <- function(input, output, session){
}
shinyApp(ui, server)
感谢您在修复代码方面获得的任何帮助。
【问题讨论】: