使用conditionalPanel后Shiny仪表盘内容不显示的问题排查
问题原因与解决方法
错误点1:条件表达式语法错误
你的conditionalPanel条件字符串末尾缺少闭合单引号,导致前端JavaScript解析失败,直接破坏了整个UI的渲染流程,包括dashboardBody中的内容。
错误点2:sidebarMenu对应的输入ID错误
shinydashboard的sidebarMenu默认生成的输入ID是tabs,而非你写的sidebar,原条件无法正确触发面板显示。
修正后的代码
library(shiny) library(shinydashboard) ui <- dashboardPage( dashboardHeader(title="TEST"), dashboardSidebar( sidebarMenu( menuItem("tab1", tabName="tab_number1", icon=icon("arrow-right"), conditionalPanel("input.tabs === 'tab_number1'", selectInput(inputId="selection",label = "Select country:",choices ="", selected=NULL)) ) ) ), ## Body content dashboardBody( tabItems( #intro tab tabItem(tabName="tab_number1", fluidPage( fluidRow( h2("This text should appear here!!"), uiOutput("up"), plotOutput(outputId="plotnumber1"),br() )) ) ) ) ) server <- function(input, output) { } shinyApp(ui, server=server)
补充说明
修正这两个问题后,点击tab1时,dashboardBody中的文本会正常显示,同时conditionalPanel里的下拉选择框也会正确触发显示。
内容的提问来源于stack exchange,提问作者Juan Pablo Rincon
相关产品推荐
相关产品推荐

