0

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"
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
csmontt
  • 614
  • 8
  • 15
  • Hey, the error on "could not find function run_app()" usually means that the document_and_reload() function has failed. Could you paste here the whole output of running the run_dev.R script please? – Colin FAY Nov 26 '20 at 07:34
  • I edited my question to include the errors I get when running `run_dev.R`. Maybe also interesting to mention is that, even when I undid the changes that end up in the error, `run_dev.R` is still giving the same error. Thanks for taking the time to look at thsi! – csmontt Nov 26 '20 at 09:42

1 Answers1

0

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 :

  • in one of your R Scripts where you do bigrquery::DBI()
  • in your NAMESPACE where you might have importFrom(bigrquery, DBI)
  • in your @importFrom in your RScript, where you might be doing @importFrom bigrquery DBI

Removing this should solve the issue.

Cheers, Colin

Colin FAY
  • 4,849
  • 1
  • 12
  • 29
  • Thanks for the quick response, I did made the mistake of writing at some point `@importFrom bigrquery DBI` in one of my modules but then corrected it but I was still having the same error. I had to manually edit the NAMESPACE file, now it works again. – csmontt Nov 26 '20 at 10:59
  • Glad to hear that! Indeed `{roxygen2}` can sometime forget to remove elements from the NAMESPACE, so sometimes it's worth deleting it and re-run `devtools::document()` just to be sure :) – Colin FAY Nov 26 '20 at 19:41