I am using selectizeGroupUI to create dynamic filters in Shiny. The problem is I cannot set a default selection of the output and right now my app is selecting everything from both existing filters. That does not work for me because the real table with all the data is very big. So, I wonder how could I set as default a specific combination of filters which is illustrative for the user to start using the app but not as huge as selecting every single combination as it is working right now.
I know know how to set a default selection by using
selectInput(...,selected = 'table1',...)
But now I do not how to apply that logic using selectizeGroupUI.
Here you can see my code right now, which is showing all filter combinations at the same time:
library(shinyWidgets)
tf<-test_2_filtros
shinyApp(
ui = pageWithSidebar(
headerPanel("Conditional Filters"),
sidebarPanel(
selectizeGroupUI(
id = "my-filters",
inline = FALSE,
params = list(
var_one = list(inputId = "var_1", title = "Select variable 1", placeholder = 'select'),
var_two = list(inputId = "var_2", title = "Select variable 2", placeholder = 'select')
)
)
),
mainPanel(
DT::dataTableOutput("table")
)
),
server = function(input, output, session) {
res_mod <- callModule(
module = selectizeGroupServer,
id = "my-filters",
data = tf,
vars = c("var_1", "var_2")
)
output$table <- DT::renderDataTable({
req(res_mod())
mytable<-res_mod() %>%
dplyr::mutate(n = "Yes") %>%
mutate(row_num = 1:n()) %>%
tidyr::pivot_wider(names_from = var_3, values_from = n, values_fill = list(n = "No"))%>%
select(-row_num)
mytable<-DT::datatable(mytable, filter= 'top',options = list(order=list(0,'asc'), dom='t', pageLength= 100, autoWidth = TRUE),rownames = FALSE)
formatStyle(mytable, columns = NULL, fontWeight = styleEqual(c('No', 'Yes'), c('normal', 'bold')))
})
},
options = list(height = 500)
)
Here you can find my input and output:
input(tf in the code above)
var_1 | var_2 | var_3 |
---|---|---|
red | table1 | column1 |
red | table1 | column1 |
red | table1 | column1 |
blue | table2 | column2 |
blue | table2 | column2 |
blue | table2 | column2 |
green | table3 | column3 |
green | table3 | column3 |
green | table3 | column3 |
output
var_1 | var_2 | column1 | column2 | column3 |
---|---|---|---|---|
red | table1 | Yes | No | No |
red | table1 | Yes | No | No |
red | table1 | Yes | No | No |
blue | table2 | No | Yes | No |
blue | table2 | No | Yes | No |
blue | table2 | No | Yes | No |
green | table3 | No | No | Yes |
green | table3 | No | No | Yes |
green | table3 | No | No | Yes |
Thanks for any help or feedback.