0

I have similar issue to R Shiny selectInput, I would like to use the input to slice my data like this:

selectInput("category", "Choose a Category:",
                            choices = c('Any', levels(as.factor(unique(BD$DX_01_Cat))))), 

uiOutput("secondSelection")

if (input$category != "Any"){
       subsetSubsTab <<- subsetSubsTab[subsetSubsTab$DX_01_Cat==input$category];

output$secondSelection <- renderUI({
       selectInput("subdiagnosis", "Choose a Subdiagnosis:", choices = c("Any", as.character(subsetSubsTab[subsetSubsTab$DX_01_Cat==input$category, DX_01_Sub])) , selected = "Any")
     })

if (input$subdiagnosis != "Any"){
       subsetSubsTab <<- subsetSubsTab[subsetSubsTab$DX_01_Sub==input$subdiagnosis];
     }

but the last if statement does not work.

I get warning Warning: Error in if: argument is of length zero, the subsetSubsTab actualize for a second and goes back. Could someone help please?

  • A simplification, replace `choices = c('Any', levels(as.factor(unique(BD$DX_01_Cat)))))` with `choices = c('Any', (unique(BD$DX_01_Cat))` – Gregor Thomas Sep 24 '19 at 17:19
  • Can't really tell without a more complete example, but it seems like once your data is filtered, there's no one to go back to the original. You overwrite `subsetSubs` which each subset, so it can only get smaller... – Gregor Thomas Sep 24 '19 at 17:20
  • Since your error is with the `if` statement using `input$subdiagnosis` (you say), it would be nice if you showed that `selectInput` instead of just the `category` selector, which you say is working... – Gregor Thomas Sep 24 '19 at 17:22

0 Answers0