0

I have created a simply Shiny application that connects to my database and produces a table given an SQL query:

  ui <- fluidPage(
    textAreaInput("query", "SQL query"),
    actionButton("submit", "Submit query"),
    dataTableOutput("queryResults")
  )
  server <- function(input, output, session) {
    json="path/to/servicetoken.json"

    bigrquery::bq_auth(path = json)
    con <- DBI::dbConnect(
        bigrquery::bigquery(),
        project = "projectid",
        dataset="dataset",
        billing="projectid"
    )

    query <- eventReactive(input$submit, input$query)

    output$queryResults <- renderDataTable({
      query <- query()
      DBI::dbGetQuery(con, query)
      })

  }
  shinyApp(ui, server, ...)

This works great for just me. Every query sent to BigQuery bills me. However, what I would ideally like to do is bill those making the query. What is the best way to bill another Google user running queries via my Shiny application?

Sakshi Gatyan
  • 1,903
  • 7
  • 13
Dylan Russell
  • 936
  • 1
  • 10
  • 29
  • I would run queries that users submit as dry runs first to get the BQ usage information and then run the actual queries for them. Store the dry run info and calculate the cost from that. – randomdatascientist Nov 15 '21 at 04:11
  • Is there no way to force the login of another Google user with their own ‘projectid’ that I could pass to the billing argument? – Dylan Russell Nov 15 '21 at 05:20
  • I'm not sure... but even if there is, every user would need to have the appropriate permissions to access your BigQuery tables/datasets. Since it's an app you're creating maybe you can create a subscription type model instead of pay-per-run and charge more than just your infrastructure costs. – randomdatascientist Nov 15 '21 at 23:23
  • Yes I think Im going to get around this by having users log in with a user name password then simply use the BQ logs to match queries sent via Shiny to queries logged in BQ and charge each user individually that way. – Dylan Russell Nov 16 '21 at 00:32

0 Answers0