当我在侧边栏菜单中输入时,UI不会更新页面。在下面的示例中,当我点击"加载数据"它仍然显示页面上的菜单。
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
menuItem("About", tabName = "a", icon = icon("info-circle")),
menuItem("Load Data", icon = icon("gear"), tabName = "b",
selectInput(inputId="convertToLog", label="Are X values on log2 scale?",choices=list('Yes'=1,'No'=0),selected=1))
)),
dashboardBody(
tabItems(
tabItem(tabName ="a", "a menu"),
tabItem(tabName ="b", "b menu")
)
)
)
server <- function(input, output) {}
shinyApp(ui, server)
答案 0 :(得分:2)
据我所知,您可以/不应该在menuItem
中添加其他项目,subMenuItems
除外。您可以使用conditionalPanel
来实现您想要的效果:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(id="mysidebar",
menuItem("About", tabName = "a", icon = icon("info-circle")),
menuItem("Load Data", icon = icon("gear"), tabName = "b"),
conditionalPanel("input.mysidebar == 'b'",
selectInput(inputId="convertToLog", label="Are X values on log2 scale?",choices=list('Yes'=1,'No'=0),selected=1)),
menuItem('Another tab',tabName='c',icon = icon("gear"))
)
),
dashboardBody(
tabItems(
tabItem(tabName ="a", "a menu"),
tabItem(tabName ="b", "b menu"),
tabItem(tabName ="c", "c menu")
)
)
)
server <- function(input, output) {}
shinyApp(ui, server)
请注意,我在sidebarMenu
的条件下提供了conditionalPanel
个ID,我添加了一个标签,表明conditionalPanel
不必位于底部菜单。
我希望这有帮助!