sidebarMenu上的ConditionalPanel无法自动工作

时间:2019-04-06 10:01:23

标签: r shiny shinydashboard

我有一个闪亮的应用程序,它根据用户从conditionalPanel的选择中使用selectInput,如下所示:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
      dashboardHeader(),
         dashboardSidebar(
          sidebarMenu(      
            selectInput(
              inputId="selectCompany",
              label=" Choose Comanpany", selected = NULL,
              choices=c("HP", "Nokia", "Samsung", "Erickson")),
           uiOutput("ui")
           ),
  conditionalPanel(
       "input.selectCompany == 'HP'",
           sidebarMenu(id = "sidebarmenu",
              menuItem("User", tabName = "userComputer", icon = icon("file-text-o")))),    

   conditionalPanel(
        "input.selectCompany != 'HP'",
          sidebarMenu(id = "sidebarmenu",
              menuItem("User", tabName = "userPhone", icon = icon("file-text-o"))))),    

dashboardBody(    
tabItems(
  tabItem(tabName = "userComputer",
          fluidRow(
            column( width=9,
                    tabBox(
                      width="100%",                          
                      tabPanel("Personal Details"),
                      tabPanel("Personal data"),
                      tabPanel("Table")
                      )))),

  tabItem(tabName = "userPhone",
          fluidRow(
            column( width=9,
                    tabBox(
                      width="100%",                          
                      tabPanel("Personal Details"),
                      tabPanel("Personal data")

                    )))))))

  server <- function(input, output) {}
  shinyApp(ui, server)

条件式不能自动运行,因此无需单击“用户”菜单项,就可以在"HP""Nokia"中进行选择,选项卡不会自动从3变为2。

我尝试如下使用RenderUI并具有相同的行为:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(
sidebarMenu(      
  selectInput(
    inputId="selectCompany",
    label=" Choose Comanpany", selected = NULL,
    choices=c("HP", "Nokia", "Samsung", "Erickson")),
  uiOutput("ui")
)
  ),
     dashboardBody(
      tabItems(
        tabItem(tabName = "userComputer",              
          fluidRow(
            column( width=9,
                    tabBox(
                      width="100%",                          
                      tabPanel("Personal Details"),                      
                      tabPanel("Personal data"),
                      tabPanel("Table")

                    )))),

  tabItem(tabName = "userPhone",

          fluidRow(
            column( width=9,
                    tabBox(
                      width="100%",                          
                      tabPanel("Personal Details"),
                      tabPanel("Personal data")
                        )))))))        


  server <- function(input, output) {
   output$ui <- renderUI({    
if( input$selectCompany == "Nokia" | input$selectCompany == "Samsung" |input$selectCompany == "Erickson"){

  sidebarMenu(        
    menuItem("User", tabName = "userPhone", icon = icon("file-text-o")))

}else{
  sidebarMenu(        
    menuItem("User", tabName = "userComputer", icon = icon("file-text-o")))
   } 
    }) 
  }
  shinyApp(ui, server)  

我也尝试过使用ObserveEvent方法,但是结果还是一样,有没有一种方法可以根据selectInput的选择自动显示不同的选项卡项目,而无需单击菜单项?

0 个答案:

没有答案