用户界面无法更新闪亮仪表板

时间:2017-12-13 05:27:48

标签: r shiny shinydashboard

当我在侧边栏菜单中输入时,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)

1 个答案:

答案 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不必位于底部菜单。

我希望这有帮助!