Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.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
R 更新输入默认值选择所有选项_R_Shiny - Fatal编程技术网

R 更新输入默认值选择所有选项

R 更新输入默认值选择所有选项,r,shiny,R,Shiny,我知道在StackExchange()上有一个非常类似的问题,但是,该解决方案不能应用于我的问题。 我有一个基于两个输入的输入。在updatePickerInput上,我有shinyWidgets的selectAll和clearAll按钮。我希望selectAll是默认值,但由于它是动态的,我不知道如何将我的选择传递到所选选项中 以下是我的相关ui代码: radioButtons(inputId = 'selected_group', label = 'group', choices = '')

我知道在StackExchange()上有一个非常类似的问题,但是,该解决方案不能应用于我的问题。 我有一个基于两个输入的输入。在updatePickerInput上,我有shinyWidgets的selectAll和clearAll按钮。我希望selectAll是默认值,但由于它是动态的,我不知道如何将我的选择传递到所选选项中

以下是我的相关ui代码:

radioButtons(inputId = 'selected_group', label = 'group', choices = '')
这是我的观察事件代码:

observeEvent(c(input$selected_tab,input$selected_group),{
    req(input$selected_group)

    updatePickerInput(
        session,
        'selected_subgroup',
        choices = df %>%
            filter(tab == input$selected_tab) %>%
            filter(group == input$selected_group) %>%
            select(subgroup) %>%
            distinct(subgroup) %>%
            arrange(subgroup) %>%
            .[[1]]
    )
})

要动态选择所有选项,您需要将相同的信息传递给
updatePickerInput
选项
选定的
参数:

library(shiny)
library(datasets)
library(shinyWidgets)

statesDF <- data.frame(region = state.region, name = state.name, area = state.area, stringsAsFactors = FALSE)

ui <- fluidPage(
  radioButtons(inputId = 'selected_group', label = 'group', choices = unique(statesDF$region)),
  pickerInput(inputId = 'selected_subgroup', label = 'subgroup', choices = NULL, selected = NULL, multiple = TRUE)
)

server <- function(input, output, session) {
  filteredChoices <- reactive({
    statesDF$name[statesDF$region == input$selected_group]
  })

  observeEvent(filteredChoices(), {
    updatePickerInput(session, inputId = 'selected_subgroup', label = 'subgroup', choices = filteredChoices(), selected = filteredChoices())
  })

}

shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(数据集)
图书馆(shinyWidgets)

statesDF将用于选择的过滤后的
df
传递给
selected
?该df稍后将在reactive()语句中过滤。这里是未过滤的。请看下面我的答案中的例子来澄清。