rshinybigrquerygolem

How to read data from Bigquery into Shiny App made with Golem


I am trying to read data from a Bigquery table into a Shiny App following Golem's framework.

This can be easily done by adding the following code before the ui and server functions in an App.R file

bq_auth(path = "xxxxxxxxxxxx.json") # authenticating biqrquery with service account json file

# Establishing connection
con <- dbConnect(
           bigrquery::bigquery(),
           project = "project id",
           dataset = "dataset name",
           billing = "project id"
)

But I am a little bit lost on how is the way to do it when using Golem.

Following this thread I created a reactiveValue() on the app_server.R file.

#' The application server-side
#' 
#' @param input,output,session Internal parameters for {shiny}. 
#'     DO NOT REMOVE.
#' @import shiny
#' @import bigrquery  
#' @noRd

app_server <- function( input, output, session ) {
# Your application server logic 
bq <- reactiveValues()

observe({

    bq$con <- dbConnect(drv = bigquery(),
                    project = "project_id",
                    dataset = "datset_id",
                    billing = "project_id")

})

}

I also imported bigrquery but this has seem to broke something as now I get the following errors when I run run_dev.R:

> golem::document_and_reload()
Loading Dashboard
Error : object ‘DBI’ is not exported by 'namespace:bigrquery'
-- Error documenting your package ----------------------------------------------------------------
> 
> # Run the application
> run_app()
Error in run_app() : could not find function "run_app"

Solution

  • Here is the issue, based on your error:

    > golem::document_and_reload()
    Loading Dashboard
    Error : object ‘DBI’ is not exported by 'namespace:bigrquery'
    -- Error documenting your package --
    

    Somewhere in your code, you're trying to call bigrquery::DBI(), but it's not a function from this package. Hence the error with {golem}: you can't load everything if you have a namespace error :)

    You should either find this code error in :

    Removing this should solve the issue.

    Cheers, Colin