Skip to content

Commit

Permalink
Merge pull request #1 from thewileylab/dev
Browse files Browse the repository at this point in the history
Update Package Structure/Documentation
  • Loading branch information
the-mayer committed Mar 18, 2021
2 parents c4a21f3 + 9fbc158 commit a30a450
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 143 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shinyBigQuery
Title: shinyBigQuery: Access Google BigQuery through R Shiny
Version: 0.0.3.0000
Version: 0.0.4.0000
Authors@R: c(
person('David', 'Mayer', email = 'david.mayer@cuanschutz.edu', role = c('cre', 'aut')),
person(given = "The Wiley Lab", role = c("cph", "fnd"))
Expand All @@ -16,7 +16,7 @@ Imports:
dplyr (>= 1.0.0),
gargle,
glue,
golem (>= 0.2.1.90),
golem,
httr,
jsonlite,
magrittr,
Expand All @@ -25,14 +25,14 @@ Imports:
shiny (>= 1.5.0),
shinycssloaders (>= 1.0.0),
shinydashboard,
shinydashboardPlus,
shinydashboardPlus (>= 2.0.0),
shinyjs,
shinyWidgets,
shinyWidgets (>= 0.6.0),
tibble,
tidyr (>= 1.1.0)
Remotes: Thinkr-open/golem
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
URL: https://shinybigquery.thewileylab.org, https://github.com/thewileylab/shinyBigQuery
BugReports: https://github.com/thewileylab/shinyBigQuery/issues
Expand Down
8 changes: 3 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Generated by roxygen2: do not edit by hand

S3method(print,hidden_fn)
export(bigquery_setup_server)
export(bigquery_setup_ui)
export(installed_app)
export(run_app)
import(shiny)
importFrom(DBI,dbConnect)
Expand All @@ -12,6 +8,7 @@ importFrom(bigrquery,bq_auth)
importFrom(bigrquery,bq_project_datasets)
importFrom(bigrquery,bq_projects)
importFrom(bigrquery,dbDisconnect)
importFrom(config,get)
importFrom(dplyr,filter)
importFrom(dplyr,pull)
importFrom(gargle,token_userinfo)
Expand All @@ -36,7 +33,8 @@ importFrom(shinyWidgets,useShinydashboard)
importFrom(shinyWidgets,useShinydashboardPlus)
importFrom(shinycssloaders,withSpinner)
importFrom(shinydashboard,box)
importFrom(shinydashboardPlus,widgetUserBox)
importFrom(shinydashboardPlus,userBox)
importFrom(shinydashboardPlus,userDescription)
importFrom(shinyjs,hidden)
importFrom(shinyjs,hide)
importFrom(shinyjs,runjs)
Expand Down
2 changes: 2 additions & 0 deletions R/app_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ app_sys <- function(...){
#' @param config R_CONFIG_ACTIVE value.
#' @param use_parent Logical, scan the parent directory for config file.
#'
#' @importFrom config get
#'
#' @noRd
get_golem_config <- function(
value,
Expand Down
233 changes: 145 additions & 88 deletions R/mod_BigQuery_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
# Helpers ----
#' Installed App
#'
#' Invisibly returns an OAuth app
#'
#' @return An Invisible OAuth consumer application, produced by [httr::oauth_app()]
#'
#' @export
#' @keywords internal
#' Invisibly returns an OAuth app.
#'
#' @rdname internal-assets
#' @keywords internal
#'
#' @return An Invisible OAuth consumer application, produced by [httr::oauth_app()]
#'

installed_app <- function() {
sbqoa()
}
#' @export
#' @keywords internal

#' @rdname internal-assets
#' @keywords internal
#'
#' @noRd
print.hidden_fn <- function(x, ...) {
x <- 'Nope'
Expand All @@ -31,8 +33,7 @@ print.hidden_fn <- function(x, ...) {
#' @importFrom shinyjs useShinyjs
#' @importFrom shinyWidgets useShinydashboard useShinydashboardPlus
#' @noRd
sbq_add_external_resources <- function(){

sbq_add_external_resources <- function() {
add_resource_path(
'www', app_sys('app/www')
)
Expand All @@ -46,16 +47,67 @@ sbq_add_external_resources <- function(){
)
}

# UI ----
#' BigQuery Setup UI
#'
#' This module is designed to guide a user through the process of authenticating with Google BigQuery. It is responsible for returning an authorization token, the user selected project,the user selected dataset, and a DBI connection to a BigQuery Dataset.
#'
# Module Documentation ----
#' Google BigQuery Database Module
#'
#' @description
#'
#' This module is designed to guide a user through the process of authenticating with
#' Google BigQuery. It is responsible for retrieving:
#' \itemize{
#' \item{An OAuth 2.0 authorization token}
#' \item{A list of GCP projects that are available to the authenticated user}
#' \item{A list of BigQuery datasets contained within available projects}
#' }
#' The user is visually guided through the authentication process. Once authenticated,
#' the user is presented with project/dataset selections and once configured a
#' [DBI::dbConnect()] object is returned.
#'
#' This module consists of the following components:
#'
#' ## Module UI function
#'
#' \itemize{
#' \item{`bigquery_setup_ui`}: A uiOutput responsible for guiding a user through
#' the Google OAuth 2.0 authorization flow and graphically selecting a Google Big
#' Query project/dataset.
#' }
#' ## Module Server function
#' \itemize{
#' \item{`bigquery_setup_server`}: The logic that controls the graphical user
#' interface, including redirecting to Google, receiving an authorization code,
#' requesting an authorization token, and authenticating the application.
#' Ultimately responsible for returning public Google user information and a
#' [DBI::dbconnect()] object used to connect to the configured BigQuery database.
#' }
#'
#' @param id The module namespace
#' @name mod_bigquery
#'
#' @return
#' *bigquery_setup_ui*:
#' \item{tagList}{The Google BigQuery Setup UI}
#' *bigquery_setup_server*:
#' \item{reactiveValues}{
#' \itemize{
#' \item{moduleName}: A string, containing the module moniker.
#' \item{moduleType}: A string, with the module type (what does it do?)
#' \item{setup_ui}: The module setup ui function
#' \item{is_connected}: A string, with module connection status. Valid statuses are
#' 'yes' or 'no'.
#' \item{db_con}: A [DBI::dbConnect] object, containing the user configured BigQuery
#' connection information.
#' \item{user_info}: A list, containing public user information from Google about
#' the currently authenticated user.
#' }}
#'
NULL
#> NULL

# UI ----
#' @rdname mod_bigquery
#'
#' @return The BigQuery Setup UI
#' @keywords internal
#' @export
#'
#' @importFrom shinydashboard box
#' @importFrom shinyjs hidden
Expand All @@ -79,14 +131,12 @@ bigquery_setup_ui <- function(id) {
}

# Server ----
#' BigQuery Setup Server
#'
#' @param id The Module namespace
#' @param secrets_json Location of Google secrets json. Defaults to '/srv/shiny-server/.bq_client_id/client_secret.json' for Shiny Server installations.
#'
#' @return BigQuery connection variables and user information
#' @rdname mod_bigquery
#'
#' @keywords internal
#' @export
#'
#' @param secrets_json A string, containing the location of Google secrets json. Defaults
#' to '/srv/shiny-server/.bq_client_id/client_secret.json' for Shiny Server installations.
#'
#' @importFrom bigrquery bq_auth bq_projects bq_project_datasets bigquery dbDisconnect
#' @importFrom DBI dbConnect
Expand All @@ -99,7 +149,7 @@ bigquery_setup_ui <- function(id) {
#' @importFrom purrr flatten
#' @importFrom rlang .data
#' @importFrom shinyjs runjs show hide
#' @importFrom shinydashboardPlus widgetUserBox
#' @importFrom shinydashboardPlus userBox userDescription
#' @importFrom shinyWidgets actionBttn
#' @importFrom tibble enframe
#' @importFrom tidyr unnest
Expand Down Expand Up @@ -289,40 +339,44 @@ bigquery_setup_server <- function(id, secrets_json = '/srv/shiny-server/.bq_clie
} else {
tagList(
div(
shinydashboardPlus::widgetUserBox(title = bigquery_export$user_info$name,
width = 12,
subtitle = bigquery_export$user_info$email,
src = bigquery_export$user_info$picture,
type = 2,
color = 'primary',
collapsible = FALSE,
HTML(glue::glue('{bigquery_export$user_info$given_name}, you have successfully authenticated with Google BigQuery. Please select a dataset from from the list of available projects, or sign out and sign in with a different Google Account.<br><br>')),
br(),
selectizeInput(inputId = ns('bq_project_id'),
label = 'Select from Available Google Projects:',
choices = bigquery_setup$bq_projects,
options = list(create = FALSE,
placeholder = 'No Available Projects')
),
selectizeInput(inputId = ns('bq_dataset_id'),
label = 'Select from Available BigQuery Datasets:',
choices = NULL
),
shinyjs::hidden(
div(id = ns('bq_connect_div'),
actionButton(inputId = ns('bq_connect'),label = 'Connect',icon = icon('cloud'))
)
),
footer = fluidRow(
div(actionBttn(inputId = ns('logout'),
label = 'Sign Out of Google',
style = 'jelly',
icon = icon(name = 'sign-out-alt')
),
style="float:right;margin-right:20px"
)
)
),
shinydashboardPlus::userBox(
title = userDescription(
title = bigquery_export$user_info$name,
subtitle = bigquery_export$user_info$email,
image = bigquery_export$user_info$picture,
type = 2),
width = 12,
status = 'primary',
collapsible = FALSE,
HTML(glue::glue('{bigquery_export$user_info$given_name}, you have successfully authenticated with Google BigQuery. Please select a dataset from from the list of available projects, or sign out and sign in with a different Google Account.<br><br>')),
br(),
selectizeInput(inputId = ns('bq_project_id'),
label = 'Select from Available Google Projects:',
choices = bigquery_setup$bq_projects,
options = list(create = FALSE,
placeholder = 'No Available Projects')
),
selectizeInput(inputId = ns('bq_dataset_id'),
label = 'Select from Available BigQuery Datasets:',
choices = NULL
),
shinyjs::hidden(
div(
id = ns('bq_connect_div'),
actionButton(inputId = ns('bq_connect'),label = 'Connect',icon = icon('cloud'))
)
),
footer = fluidRow(
div(
actionBttn(inputId = ns('logout'),
label = 'Sign Out of Google',
style = 'jelly',
icon = icon(name = 'sign-out-alt')
),
style="float:right;margin-right:20px"
)
)
),
style = 'margin-left:-15px;margin-right:-15px'
)
)
Expand Down Expand Up @@ -369,35 +423,38 @@ bigquery_setup_server <- function(id, secrets_json = '/srv/shiny-server/.bq_clie
google_configured_ui <- reactive({
req(bigquery_export$is_connected == 'yes')
tagList(
shinydashboardPlus::widgetUserBox(title = bigquery_export$user_info$name,
width = 12,
subtitle = bigquery_export$user_info$email,
src = bigquery_export$user_info$picture,
type = 2,
color = 'primary',
collapsible = FALSE,
HTML(paste('<H3>Success!!</H3>',
'You have connected to a Google BigQuery database.',
'<br>',
'<br>',
'<H4>Connection Information:</H4>',
'<b>Project:</b>', bigquery_setup$bq_project_id,
'<br>',
'<b>Dataset:</b>', bigquery_setup$bq_dataset_id,
'<br>'
)
),
actionButton(inputId = ns('sbq_disconnect'), label = 'Disconnect'),
footer = fluidRow(
div(actionBttn(inputId = ns('logout_2'),
label = 'Sign Out of Google',
style = 'jelly',
icon = icon(name = 'sign-out-alt')
),
style="float:right;margin-right:20px"
)
)
)
shinydashboardPlus::userBox(
title = userDescription(
title = bigquery_export$user_info$name,
subtitle = bigquery_export$user_info$email,
image = bigquery_export$user_info$picture,
type = 2),
width = 12,
status = 'primary',
collapsible = FALSE,
HTML(paste('<H3>Success!!</H3>',
'You have connected to a Google BigQuery database.',
'<br>',
'<br>',
'<H4>Connection Information:</H4>',
'<b>Project:</b>', bigquery_setup$bq_project_id,
'<br>',
'<b>Dataset:</b>', bigquery_setup$bq_dataset_id,
'<br>'
)
),
actionButton(inputId = ns('sbq_disconnect'), label = 'Disconnect'),
footer = fluidRow(
div(
actionBttn(inputId = ns('logout_2'),
label = 'Sign Out of Google',
style = 'jelly',
icon = icon(name = 'sign-out-alt')
),
style="float:right;margin-right:20px"
)
)
)
)
})

Expand Down
2 changes: 2 additions & 0 deletions R/run_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' @export
#' @importFrom shiny shinyApp
#' @importFrom golem with_golem_options
#'
#' @return No return value, called to start the Shiny Application!
run_app <- function(...) {
with_golem_options(
app = shinyApp(
Expand Down
5 changes: 5 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
bigquery
bq
GCP
httr
json
moduleName
moduleType
oauth
OAuth
shinyBigQuery’
srv
ui
UI
uiOutput
Binary file added inst/app/www/wl_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion inst/golem-config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
default:
golem_name: shinyBigQuery
golem_version: 0.0.0.9000
golem_version: 0.0.4.0000
app_prod: no
production:
app_prod: yes
Expand Down
Loading

0 comments on commit a30a450

Please sign in to comment.