Changing the filter names and its values as per the values selected from another filter

I have a dataframe df. I have executed half the code like below. With this code what I get is 3 filters

Now When I select Trend in Filter1, there is a plot displayed in chart A. With this plot, when i change values in below filter(Trend), the plot is getting changed, This is fine for me.

What I want is, in Filter1 if Trend is selected, the name of the below Filter should get changed to Trend and also its values should be changed to as per whatever is given in UI.(Something like below).
So if I select Correlation in FIlter1 the name of the below filter should get changed to Correlation and its values as well. In other words, I do not need 3rd Filter here. Also in correlation filter, there is a combination of all possible factors. So when I select C&D the plot should show the relation between A and B and so on.

Below is the original code

  title: Current Conditions
   orientation: columns
   vertical_layout: scroll
   runtime: shiny
   source_code: embed
   theme: cosmo

   ```{r global}

   df <- structure(list(A = c(1, 2, 3, 4, 5, 6, 7), B = c(3, 4, 5, 12, 
   23, 12, 13), C = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L), .Label = c("A", 
   "B", "C"), class = "factor"), D = structure(c(2L, 2L, 1L, 1L, 
   3L, 3L, 3L), .Label = c("A", "B", "C"), class = "factor")), class = "data.frame", row.names =             c(NA, 
   df <-


  Inputs {.sidebar}

    selectInput("c","Filter1",choices = c("","Trend","Correlation"))
    selectInput("b","Filter2",choices = c("ALL",levels(factor(df$C))))
    selectInput("d","Correlation",choices = c("",combn(names(df),2,paste,collapse="&")))

  Column {data-width=350}

  ### Chart A

  output$p1 <- renderPlot({
     if (input$c == "Trend"){
    s_data <- df
  if (input$c == "Trend" && input$b != "ALL") {
      s_data <- s_data %>% 
          filter(C %in% input$b)


Hope my question is clear

Hi @vinayprakash808. You may use a reactive expression to assign the label of the selectInput b.

  bLabel <- reactive({
    if(isTruthy(input$c)) {
    } else {
    selectInput("c","Filter1",choices = c("","Trend","Correlation"))
    renderUI(selectInput("b", bLabel(), choices = c("ALL",levels(factor(df$C)))))
    selectInput("d","Correlation",choices = c("",combn(names(df),2,paste,collapse="&")))

Thanks for this information. But also I need to the values to change when it turned to "Correlation". The values under correlation should be " combn(names(df),2,paste,collapse="&")"

Basically, the values should changes as per the filters.

@vinayprakash808. You can make another reactive expression to assign the choices of selectInput b according to the selection of the selectInput c.

1 Like

Perfect got it thanks.

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