从 shinyWidgets 访问 selectizeGroupUI 中的单个输入时出现问题

Problem with acccesing single input in selectizeGroupUI from shinyWidgets

所以这是 selectizeGroupUI 和服务器如何工作的一个很好的例子。所有过滤器都是交互式的,并且选择会根据其他过滤器选择进行更新。但我想访问例如值 like: input$var_two 等用于其他表达式。

我正在尝试使用反引号等访问 input$my-filters 但所有内容 returns NULL


library(shiny)
library(shinyWidgets)

a_df <- tibble(
    var_one = c("hadley", "charlotte", "rené", "raymond"),
    var_two = c("mutate", "filter", "slice", "spread"),
    var_three = c("an apple", "a pipe", "a cocktail", "a dog"),
    var_four = c("with", "without", "thanks", "out of"),
    var_five = c("tidyr", "magrittr", "purrr", "dplyr")
)

ex_df <- expand.grid(a_df) # create a df with the 64 combinaisons

tib <- as_tibble(sample_n(ex_df, 40))


shinyApp(
    ui = pageWithSidebar(
        headerPanel("Painting 8"),
        sidebarPanel(
            selectizeGroupUI(
                id = "my-filters",
                inline = FALSE,
                params = list(
                    var_one = list(inputId = "var_one", title = "Select variable 1", placeholder = 'select'),
                    var_two = list(inputId = "var_two", title = "Select variable 2", placeholder = 'select'),
                    var_three = list(inputId = "var_three", title = "Select variable 3", placeholder = 'select'),
                    var_four = list(inputId = "var_four", title = "Select variable 4", placeholder = 'select'),
                    var_five = list(inputId = "var_five", title = "Select variable 5", placeholder = 'select')
                )
            )
        ),
        
        mainPanel(
            tableOutput("table")
        )
    ),
    
    server = function(input, output, session) {
        
        res_mod <- callModule(
            module = selectizeGroupServer,
            id = "my-filters",
            data = tib,
            vars = c("var_one", "var_two", "var_three", "var_four", "var_five")
        )
        
        output$table <- renderTable({
            res_mod()
        })
        
    },
    
    options = list(height = 500)
)

您可以使用括号中的两个 inputId 来访问服务器中的输入值(您需要将两个 ID 与一个 - 组合):input[["my-filters-var_two"]]

例如,我扩展了您的代码,将 input$var_two 的选定值显示为 table.

下方的文本
library(shiny)
library(shinyWidgets)

a_df <- tibble(
  var_one = c("hadley", "charlotte", "rené", "raymond"),
  var_two = c("mutate", "filter", "slice", "spread"),
  var_three = c("an apple", "a pipe", "a cocktail", "a dog"),
  var_four = c("with", "without", "thanks", "out of"),
  var_five = c("tidyr", "magrittr", "purrr", "dplyr")
)

ex_df <- expand.grid(a_df) # create a df with the 64 combinaisons

tib <- as_tibble(sample_n(ex_df, 40))


shinyApp(
  ui = pageWithSidebar(
    headerPanel("Painting 8"),
    sidebarPanel(
      selectizeGroupUI(
        id = "my-filters",
        inline = FALSE,
        params = list(
          var_one = list(inputId = "var_one", title = "Select variable 1", placeholder = 'select'),
          var_two = list(inputId = "var_two", title = "Select variable 2", placeholder = 'select'),
          var_three = list(inputId = "var_three", title = "Select variable 3", placeholder = 'select'),
          var_four = list(inputId = "var_four", title = "Select variable 4", placeholder = 'select'),
          var_five = list(inputId = "var_five", title = "Select variable 5", placeholder = 'select')
        )
      )
    ),
    
    mainPanel(
      tableOutput("table"),
      
      # SHOW SELECTED VALUE FROM var_two
      textOutput("text_var_two")
    )
  ),
  
  server = function(input, output, session) {
    
    res_mod <- callModule(
      module = selectizeGroupServer,
      id = "my-filters",
      data = tib,
      vars = c("var_one", "var_two", "var_three", "var_four", "var_five")
    )
    
    output$table <- renderTable({
      res_mod()
    })
    
    # SELECT VALUE FROM var_two
    output$text_var_two <- renderText({
      input[["my-filters-var_two"]]
      
    })
    
  },
  
  options = list(height = 500)
)