Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
条件面板引用selectInput()multiple=TRUE_R_Shiny - Fatal编程技术网

条件面板引用selectInput()multiple=TRUE

条件面板引用selectInput()multiple=TRUE,r,shiny,R,Shiny,如果在inputSelect() 使用下面的示例,Shining应用程序应该在侧边栏面板中不显示“lob_选项”或“segment_选项”过滤器的情况下启动,我有以下要求: 当在“filter_choice”过滤器中同时选择了“lob_choice”和“segment_choice”过滤器时,应同时显示这两个过滤器 “lob_选项”和“segment_选项”过滤器仅在“filter_choice”过滤器中选中时才应显示 取消选择任一选项时,应将其从侧栏面板显示中删除 在“filter_choic

如果在
inputSelect()

使用下面的示例,Shining应用程序应该在侧边栏面板中不显示“lob_选项”或“segment_选项”过滤器的情况下启动,我有以下要求:

  • 当在“filter_choice”过滤器中同时选择了“lob_choice”和“segment_choice”过滤器时,应同时显示这两个过滤器
  • “lob_选项”和“segment_选项”过滤器仅在“filter_choice”过滤器中选中时才应显示
  • 取消选择任一选项时,应将其从侧栏面板显示中删除
  • 在“filter_choice”(过滤器选择)过滤器中选择它们的顺序并不重要
  • 如果在“filter_choice”过滤器中选择了一个条件面板,则下面的代码将显示其中一个条件面板,但如果同时选择了这两个条件面板,则也不会显示

    用户界面
    ui来自
    ?条件面板

    条件将重复计算的JavaScript表达式,以确定是否应显示面板

    所以这里我们可以使用JS来检查过滤器的选择


    很好!我刚刚学会了如何使用
    input.filter\u choice.includes('LOB')
    ,这将是
    input.filter\u choice.indexOf('LOB')>=0
    ,但我正在努力找到
    input.filter\u选项!==null
    解决方案的一部分。谢谢
    ui <- fluidPage(
    
      titlePanel("Test App"),
    
      sidebarLayout(
        sidebarPanel(
          h3("Parameters"),
    
          selectInput("filter_choice", 
                      "In which ways would you like to filter the data?", 
                      c("LOB", 
                        "Segment"), 
                      selected = NULL, 
                      multiple = TRUE),
    
          conditionalPanel(condition = "input.filter_choice == 'LOB'",
                           selectInput("lob_choice", 
                                       "Choose Line(s) of Business:", 
                                       c("Brandon", "Kyler", "Trent"), 
                                       selected = NULL, 
                                       multiple = TRUE)),
    
          conditionalPanel(condition = "input.filter_choice == 'Segment'",
                           selectInput("segment_choice", 
                                       "Choose Segment(s):", 
                                       c("LA", "Inverness", "Orlando"), 
                                       selected = NULL, 
                                       multiple = TRUE))),
    
        mainPanel(tableOutput("table"))
      )
    )
    
    library(shiny)
    library(dplyr)
    
    server <- function(input, output) {
    
      datasetInput <- reactive({
    
        data <- data.frame(lob = sample(c("Brandon", "Kyler", "Trent"), 1000, replace = TRUE),
                           segment = sample(c("LA", "Inverness", "Orlando"), 1000, replace = TRUE),
                           amount = sample(c(100:10000), 1000, replace = TRUE))
    
        # Filter for LOBs if specific LOBs are selected
        if (length(input$lob_choice) > 0) {
          lob_values <- input$lob_choice
          data <- data %>% filter(lob %in% lob_values)
        }
    
        # Filter for Segments if specific Segments are selected
        if (length(input$segment_choice) > 0) {
          segment_values <- input$segment_choice
          data <- data %>% filter(segment %in% segment_values)
        }
    
        data2 <- aggregate(amount ~ lob + segment, data = data, FUN = sum)
        data2[order(-data2$amount), ]
    
      })
    
      output$table <- renderTable({
        datasetInput()    
      })
    }
    
    condition = "input.filter_choice !== null && input.filter_choice.indexOf('LOB') >= 0"
    #and
    condition = "input.filter_choice !== null && input.filter_choice.indexOf('Segment') >= 0"