R/firebase_init.R

Defines functions firebase_init

Documented in firebase_init

#' Initialize Firebase
#'
#' Executes a few lines of JavaScript to initialize Firebase. This function should be
#' called in your Shiny UI immediately after \code{\link{firebase_dependencies}}.
#'
#' @param firebase_config named \code{list} of firebase configuration values.
#' Required values are:
#' - `apiKey`
#' - `authDomain`
#' - `projectId`
#'
#' @export
#'
#' @return a character string of JavaScript code to initialize Firebase
#'
#' @importFrom htmltools tagList tags
#'
#' @examples
#'
#'
#' \dontrun{
#' my_config <- list(
#'   apiKey = "your Firebase API key",
#'   authDomain = "your Firebase auth domain",
#'   projectId = "your Firebase Project ID"
#' )
#'
#' firebase_init(my_config)
#' }
firebase_init <- function(firebase_config) {

  htmltools::tagList(
    htmltools::tags$script(
      paste0("
        var firebaseConfig = {
          apiKey: '", firebase_config$apiKey, "',
          authDomain: '", firebase_config$authDomain, "',
          projectId: '", firebase_config$projectId, "'
        }

        firebase.initializeApp(firebaseConfig)
      ")
    )
  )
}

Try the polished package in your browser

Any scripts or data that you put into this service are public.

polished documentation built on Feb. 16, 2023, 8:02 p.m.