To understand Shiny I am trying to create an app that could let the user select several of the categories of var_1 (see input below) in one select menu and then show only the available options within those categories in a second select menu. The output should show var_1 selection in the first column, var_2 on the second column, and var_3 should be shown as columns (I have used pivot_wider for this) and if the element in var_3 is present on the selection or not ("yes" or "no"). Maybe by looking at my input and output tables, I am able to explain my objective in a better way:
input(tf in the code below)
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 |
Here is the code I have used to try to build the app but I keep getting errors I will show below the code:
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(
tableOutput("table")
)
),
server = function(input, output, session) {
res_mod <- callModule(
module = selectizeGroupServer,
id = "my-filters",
data = tf,
vars = c("var_1", "var_2")
)
output$table <- renderTable({
res_mod()%>%
dplyr::mutate(n = "Yes")%>%
tidyr::pivot_wider(names_from = var_3, values_from = n, values_fill = list(n = "No"))
})
},
options = list(height = 500)
)
These are the errors and warnings I am getting right now:
Warning: Values are not uniquely identified; output will contain list-cols.
- Use
values_fn = list
to suppress this warning.- Use
values_fn = length
to identify where the duplicates arise- Use
values_fn = {summary_fun}
to summarise duplicates
Warning: Error in: Can't convert character to list.
Thanks for any suggestions you could give me.