I am currently working with a data set that is not too large (about 30,000 rows and 81 columns). I am trying to build a shiny app that subsets the dataframe based on 4 total choices (conditionally, so first filter subsets the dataframe based on the choice, only showing choices in the second dropdown that match that filter condition, and so on for the rest of the filters ) and then outputs a few tables.
(I apologize before hand for the long question and error outputs)
As of now I have built an app that works on occasion but fails in most cases. Either the R session is terminated or the after a couple of choices the app stops responding or takes extremely long to populate the subsequent menu items to choose from, eventually freezing. I am not able to figure out what the error is. Below is my app
I can share the data if needed.
ui_4 = pageWithSidebar(
headerPanel("Data overview with 4 filters "),
sidebarPanel(
uiOutput("status"), ###### these are the four filters
uiOutput("region"),
uiOutput("country"),
uiOutput("serial")
),
mainPanel(
tableOutput("table")
)
)
server_4 = function(input, output) {
####### Choosing first variable (status)
output$status <- renderUI({ selectizeInput('var1', 'Select Status', choices = c("Choose" = "", wo_rev_21_small$status))}) #####wo_rev_21_small is my dataframe
###### second choice (region)
output$region <- renderUI({
choice_region <- reactive({
wo_rev_21_small %>%
filter(status == input$var1) %>%
pull(region)})
selectizeInput('var2', 'Select region', choices = c("Choose" = "", choice_region()))})
###### Third choice (country)
output$country <- renderUI({
choice_country <- reactive({
wo_rev_21_small %>%
filter(status == input$var1) %>%
filter(region == input$var2) %>%
pull(country)})
selectizeInput('var3', 'Select Country', choices = c("Choose" = "", choice_country()))})
##### Select variable 3 (serial)
output$serial <- renderUI({
choice_sl <- reactive({
wo_rev_21_small %>%
filter(status == input$var1) %>%
filter(region == input$var2) %>%
filter(country == input$var3) %>%
pull(serial)})
selectizeInput('var4', 'Select serial ', choices = c("select" = "", choice_sl()))
})
tab <- reactive({ ###### This is where I subset the dataframe based on choices
wo_rev_21_small %>%
filter(status == input$var1) %>%
filter(region == input$var2) %>%
filter(country == input$var3) %>%
filter(serial == input$var4)
})
output$table <- renderTable({ tab() })
}
shinyApp(ui_4, server_4)
The filter does not work (or does not load quickly and correctly)most cases or if one or two levels of filters load, the rest dont, or takes extremely long time by the time I get through the choice from the drop down.
A snapshot of the command window in R studio is below
Warning: The select input "var1" contains a large number of options; consider using server-side selectize for massively improved performance. See the Details section of the ?selectizeInput help topic.
Warning: Error in filter: Problem while computing `..1 = status == input$var1`.
x Input `..1` must be of size 25545 or 1, not size 0.
141: <Anonymous>
Warning: Error in filter: Problem while computing `..1 = status == input$var1`.
x Input `..1` must be of size 25545 or 1, not size 0.
142: <Anonymous>
Warning: Error in filter: Problem while computing `..1 = status == input$var1`.
x Input `..1` must be of size 25545 or 1, not size 0.
143: <Anonymous>
Warning: Error in filter: Problem while computing `..1 = status == input$var1`.
x Input `..1` must be of size 25545 or 1, not size 0.
135: <Anonymous>
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
Warning: The select input "var2" contains a large number of options; consider using server-side selectize for massively improved performance. See the Details section of the ?selectizeInput help topic.
Warning: Error in filter: Problem while computing `..1 = region == input$var2`.
x Input `..1` must be of size 17208 or 1, not size 0.
141: <Anonymous>
Warning: Error in filter: Problem while computing `..1 = region == input$var2`.
x Input `..1` must be of size 17208 or 1, not size 0.
142: <Anonymous>
Warning: Error in filter: Problem while computing `..1 = region == input$var2`.
x Input `..1` must be of size 17208 or 1, not size 0.
134: <Anonymous>
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
Warning: The select input "var3" contains a large number of options; consider using server-side selectize for massively improved performance. See the Details section of the ?selectizeInput help topic.
Warning: Error in filter: Problem while computing `..1 = country == input$var3`.
x Input `..1` must be of size 17178 or 1, not size 0.
141: <Anonymous>
Warning: Error in filter: Problem while computing `..1 = country == input$var3`.
x Input `..1` must be of size 17178 or 1, not size 0.
133: <Anonymous>
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
As the output screen shows these warning and errors are the same for each variable as I select from the dropdown menu.
How can this be fixed? I dont think 30,000 rows is large enough to slow down the output by that much.
I have a feeling it is something to do with the way I am filtering/subsetting the data frame.
Is there a solution for this/a better way to do this?
If you have got this far, thanks for patiently going through my problem!!!!!
Thanks for any help in advance.