使用observeEvent和req()更新DF

时间:2019-02-07 14:31:21

标签: r shiny

首先,我使用该代码在 DATABASE 中搜索一些值:

 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

我要在用户输入新的Input值后更新我的 DF ,并使用 insertUI observeEvent 中调用它,例如: (继续执行代码)

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
        )
      )
    })

如何为每个用户条目更新 DF

我尝试了 req(),但它不起作用。我尝试过:

    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
        )
      )
    })

在那种情况下...我一个observeEvent等待上一个输入,然后在数据库中找到(至少可能是这样)。 但是,它导致了一个错误,我无法确定错误在哪里。

没有 req()(我的实际状态),这些值是从第一个输入的第一次搜索得出的。

有人知道解决此问题的方法吗?使用 req()或其他来源。

0 个答案:

没有答案