Problem with dplyr filter syntax

dplyr
#1

Guys,

I'm trying to filter some "choices" in my INPUT based on results of some rows in my dataframe. Look:

aqa

I need to select the AQA_QT values based on GRAU select. Ex.:
For GRAU = X65, the AQA_QT values must be "VD26", "VD51", "VS06" or "VD31".

My code:

 output$iAQA <- renderUI({
    aqas <- my_df$AQA_QT

    filter(my_df,
            GRAU == "input$graudoaco" 
          )

    selectInput(
      "aqadoaco",
      label = "Selecione AQA:",
      choices= aqas,
      multiple = F
    )
  })

That way, it's showing ALL the AQA_QT values. I tried many variations of this code.

How can I do it?
Thx.

0 Likes

#2

You're not providing much context nor have you offered a reproducible example.

If you want to filter the values where GRAU = X65, then filter(my_df, GRAU == "X65") should do the trick.

0 Likes

#3

My hunch is that you want

output$iAQA <- renderUI({

   my_df <- filter(my_df, GRAU == input$graudoaco)

    selectInput(
      "aqadoaco",
      label = "Selecione AQA:",
      choices= my_df$AQA_QT,
      multiple = F
    )
  })

Also, note that filter(my_df, GRAU == "input$graudoaco") is very different from filter(my_df, GRAU == input$graudoaco)

4 Likes

#4

Really thanks man!

You solved my problem. :grinning:

0 Likes