Dynamic filter in shiny app

I have created two different filters and I will like to develop a dynamic filter. If the dataset doesn't have one value the second/first filter must eliminate the other value from the filter. Do I need to use an observeEvent? But where?

For example, I have used the iris dataset and if I select Species setosa I will like to see only 0.1, 0.2, 0.3 etc.

library(shiny)
library(dplyr)
library(DT)
library(ggplot2)


shinyUI (fluidPage(
  navbarPage("My Application",

             tabPanel("First",
                      tabPanel("Per Famiglia Prodotto",
                               selectInput("Specie", "Per specie", choices = unique(iris$Species)),
                               
                               tabPanel("Classe2",
                                        selectInput("classe2", "Classe2", choices = unique(iris$Petal.Width)),
                                        
  
                               )
                      )
             )
  )
)
)


shinyServer(
  function(input, output, session) {
    iris

    classe <- reactive({
      filter(iris, iris$Species == input$classe)})
    
    
    classe2 <- reactive({
      filter(Dato, iris$Petal.Width == input$classe2)
    })
  })

The way you describe your requirement seems problematic because it appears to be circular. What filter 1 shows depends on what filter 2 shows depends on what filter 1 shows to infinity.

You need to conceive of a non circular approach. I.e. a heirarchy of some kind.

How can I do? Is it always a observeEvent?

I have try this in server, ui is the same. It in not working, you can see some error?

Server

classe <- reactive({
filter(iris, iris$Species == input$classe)})

observeEvent(classe(), {
  choices <- unique(classe()$Petal.Width)
  updateSelectInput(inputId = "classe2", choices = choices) 
})
   classe2 <- reactive({
     req(input$classe2)
     filter(Dato, Petal.Width == input$classe2)
   })

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.