0

I am trying to pass input values to a big query.

I tried passing reactive values and the input values directly. This works when we directly pass the vertical and kpi values.

 observeEvent(input$go, {
    vert_query <- input$vert
  })

  observeEvent(input$go, {
    kpi_query <- input$kpi
  })

  alert_query <- reactive({
    gar_auth_service(
      json_file = " ",
      scope = "https://www.googleapis.com/auth/bigquery")

    project <- "bigquery-project*" # put your project ID here


     sql <- paste0("SELECT Platform as Platform, Min(CPM) as Min_CPM, Max(CPM) as Max_CPM,  Avg(CPM) as Avg_CPM, Min(CPA) as Min_CPA, MAx(CPA) as Max_CPA, Avg(CPA) as Avg_CPA 
         FROM [bigquery-project*] where Vertical = ", input$vert," or KPI = ", input$kpi, 
              "Group BY Platform Order BY Platform")


    results <- bqr_query(projectId = project, query = sql, datasetId = "test")
    results
  })

  output$tbTable <- 
    renderTable({
      alert_query()
    })

I am expecting to see the query output in a table format

Ana
  • 325
  • 2
  • 11

1 Answers1

0

If your problem is that you cannot assign a value using "observeEvent" and only works when you put it directly, maybe this can work: the code that you would need to use would be "eventReactive" instead "observeEvent", because "observeEvent" is used when you want to perform an action in response to an event and "eventReactive" creates a reactive value that changes based on the eventExpr, you can check this information here.

Amaterasu
  • 39
  • 1