我shinyWidget
在一个闪亮的应用程序中使用了这个令人惊叹的包,特别是我正在玩弄SelectizeGroup
函数以创建一组 SelectizeInput 以过滤 data.frame。
有没有办法像我们一样为输入指定默认值selectizeInput
?
即selectizeInput
我们选择了一个参数,即
最初选择的值(或多个值,如果 multiple = TRUE)。如果未指定,则默认为单选列表的第一个值,而多选列表则没有值。
我想知道是否有类似的东西。
示例取自:https ://www.davidsolito.com/post/conditional-drop-down-in-shiny/
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)
tib <- as_tibble(sample_n(ex_df, 40))
library(shinyWidgets)
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)
)
我希望在应用程序启动时至少为第一个变量预选一个值var_one