Update DF using observeEvent and req()

database
rstudio

#1

People!

First, i search for some values in DATABASE using that code:

observeEvent(input$pesquisa,{

    query <- glue(
      "select 
      cod_ordem_producao as ORDEM,
      dim_ext_tubo as DIAMETRO,
      esp_par_tubo as PAREDE,
      cod_aqa as AQA,
      tmo_ciclo_plan as CICLO,
      dsc_aco as GRAU,
      from
      QT_QTS.PLA_ORDEM_PRODUCAO
      where DIM_EXT_TUBO = {as.numeric(input$diametro)}
      and esp_par_tubo = {as.numeric(input$parede)}
      order by DTH_CRIACAO_REG desc")

    df <- dbGetQuery(
      connection_reportUser,
      query
    )

    df

I want to update my DF after the user enter with a new value of Input, called in an observeEvent with insertUI , like: (continuing the code)

observeEvent(input$pesquisa, {

      insertUI(
        selector = "#pesquisa",
        where = "afterEnd",
        ui = selectInput(
          "grau",
          label = "Grau:",
          choices = df$GRAU
        )
      )
    })

    observeEvent(input$buscaaqa, {

      insertUI(
        selector = "#buscaaqa",
        where = "afterEnd",
        ui = selectInput(
          "aqa",
          label = "AQA:",
          choices = df$AQA
        )
      )
    })

    observeEvent(input$buscaciclo, {

      insertUI(
        selector = "#buscaciclo",
        where = "afterEnd",
        ui = selectInput(
          "aqa",
          label = "Ciclo:",
          choices = df$CICLO
        )
      )
    })

How can I update my DF with each user entry?

I tried with req() , but it just not work. I tried:

observeEvent(input$pesquisa, {

      insertUI(
        selector = "#pesquisa",
        where = "afterEnd",
        ui = selectInput(
          "grau",
          label = "Grau:",
          choices = df$GRAU
        )
      )
    })

    observeEvent(input$buscaaqa, {

  {req(input$grau) 
        query <- glue(
          "select 
      cod_aqa as AQA,
      from
      QT_QTS.PLA_ORDEM_PRODUCAO
      where dsc_aco = {as.character(input$grau)}")

        df <- dbGetQuery(
          connection_reportUser,
          query
        )

        df

      }

      insertUI(
        selector = "#buscaaqa",
        where = "afterEnd",
        ui = selectInput(
          "aqa",
          label = "AQA:",
          choices = df$AQA
        )
      )
    })

    observeEvent(input$buscaciclo, {

  {req(input$aqa) 
        query <- glue(
          "select 
      AQA,
      from
      QT_QTS.PLA_ORDEM_PRODUCAO
      where grau = {as.character(input$grau)}")

        df <- dbGetQuery(
          connection_reportUser,
          query
        )

        df

      }

      insertUI(
        selector = "#buscaciclo",
        where = "afterEnd",
        ui = selectInput(
          "aqa",
          label = "Ciclo:",
          choices = df$CICLO
        )
      )
    })

In that case... one observeEvent wait for the previous input and then find in the DATABASE (at least, that may be the idea). But, it cause an error that i could not identify where is the mistake.

Without the req() (my acctual state), the values are comming from the first search from the first input.

Does anyone know some method to solve this problem? Using req() or using another source.