| Title: | Connect to 'Google Firebase' |
|---|---|
| Description: | Provides an interface to 'Google Firebase' services <https://firebase.google.com/>, including 'Firebase Realtime Database', 'Cloud Firestore', 'Firebase Authentication', and 'Cloud Storage for Firebase'. Supports interactive use and 'shiny' applications as well as automated server-side workflows. Data frames and objects can be stored and retrieved, users can be authenticated, and files can be managed through the services' application programming interfaces. |
| Authors: | Robin Gounder [aut, cre] (ORCID: <https://orcid.org/0009-0008-7755-7081>), Paul Spende [aut], Kevin McGinley [ctb] |
| Maintainer: | Robin Gounder <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 2.0.2 |
| Built: | 2026-09-29 21:03:45 UTC |
| Source: | https://github.com/cran/fireData |
Legacy anonymous login. Use auth_anonymous() instead.
anonymous_login(project_api)anonymous_login(project_api)
project_api |
The Firebase Project API key |
Authentication response
Legacy authentication function. Use auth_sign_in() instead.
auth(projectAPI, email = "prompt", password = "prompt")auth(projectAPI, email = "prompt", password = "prompt")
projectAPI |
The Firebase Project API key |
email |
User email |
password |
User password |
Authentication response
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { auth(projectAPI = "AIzaSy...", email = "[email protected]", password = "password") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { auth(projectAPI = "AIzaSy...", email = "[email protected]", password = "password") }
Signs in a user anonymously. Anonymous users can be upgraded to full accounts later by linking credentials.
auth_anonymous(conn = NULL, api_key = NULL)auth_anonymous(conn = NULL, api_key = NULL)
conn |
Firebase connection object (or NULL to use config) |
api_key |
Firebase API key (used if conn is NULL) |
Authentication response containing idToken, refreshToken, and localId
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "AIzaSy...") result <- auth_anonymous(conn) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "AIzaSy...") result <- auth_anonymous(conn) }
Creates a new user account with email and password.
auth_create_user(conn = NULL, email = NULL, password = NULL, api_key = NULL)auth_create_user(conn = NULL, email = NULL, password = NULL, api_key = NULL)
conn |
Firebase connection object (or NULL to use config) |
email |
User email address |
password |
User password (min 6 characters) |
api_key |
Firebase API key (used if conn is NULL) |
Registration response containing idToken, email, refreshToken, expiresIn, and localId
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "AIzaSy...") result <- auth_create_user(conn, "[email protected]", "password123") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "AIzaSy...") result <- auth_create_user(conn, "[email protected]", "password123") }
Deletes the authenticated user's account.
auth_delete_user(conn = NULL, id_token = NULL, api_key = NULL)auth_delete_user(conn = NULL, id_token = NULL, api_key = NULL)
conn |
Firebase connection object with valid token |
id_token |
ID token (used if conn doesn't have token) |
api_key |
Firebase API key |
Empty response on success
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { auth_delete_user(conn) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { auth_delete_user(conn) }
Retrieves account info for the currently authenticated user.
auth_get_user(conn = NULL, id_token = NULL, api_key = NULL)auth_get_user(conn = NULL, id_token = NULL, api_key = NULL)
conn |
Firebase connection object with valid token |
id_token |
ID token (used if conn doesn't have token) |
api_key |
Firebase API key |
User account information
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { user_info <- auth_get_user(conn) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { user_info <- auth_get_user(conn) }
Initiates Google OAuth flow and signs in to Firebase.
auth_google( conn = NULL, client_id = NULL, client_secret = NULL, request_uri, redirect_uri = httr::oauth_callback(), return_idp_credential = TRUE, cache = FALSE, api_key = NULL )auth_google( conn = NULL, client_id = NULL, client_secret = NULL, request_uri, redirect_uri = httr::oauth_callback(), return_idp_credential = TRUE, cache = FALSE, api_key = NULL )
conn |
Firebase connection object (or NULL to use config) |
client_id |
Google OAuth client ID |
client_secret |
Google OAuth client secret |
request_uri |
Request URI for OAuth callback |
redirect_uri |
Redirect URI (defaults to httr callback) |
return_idp_credential |
Whether to return OAuth credentials |
cache |
Whether to cache the OAuth token |
api_key |
Firebase API key |
Authentication response
if (interactive()) { # Requires a configured Firebase project and OAuth client credentials. result <- auth_google( conn, client_id = "your-client-id.apps.googleusercontent.com", client_secret = "your-secret", request_uri = "http://localhost" ) }if (interactive()) { # Requires a configured Firebase project and OAuth client credentials. result <- auth_google( conn, client_id = "your-client-id.apps.googleusercontent.com", client_secret = "your-secret", request_uri = "http://localhost" ) }
Signs in a user with OAuth credentials from a third-party provider.
auth_oauth( conn = NULL, request_uri, post_body, return_idp_credential = TRUE, api_key = NULL )auth_oauth( conn = NULL, request_uri, post_body, return_idp_credential = TRUE, api_key = NULL )
conn |
Firebase connection object (or NULL to use config) |
request_uri |
The URI to which the IDP redirects the user back |
post_body |
OAuth credential (ID token or access token) and provider ID |
return_idp_credential |
Whether to return the OAuth credential |
api_key |
Firebase API key |
Authentication response
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # After obtaining OAuth token from provider post_body <- "id_token=<google_id_token>&providerId=google.com" result <- auth_oauth(conn, "http://localhost", post_body) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # After obtaining OAuth token from provider post_body <- "id_token=<google_id_token>&providerId=google.com" result <- auth_oauth(conn, "http://localhost", post_body) }
Refreshes an expired ID token using a refresh token.
auth_refresh_token(conn = NULL, refresh_token, api_key = NULL)auth_refresh_token(conn = NULL, refresh_token, api_key = NULL)
conn |
Firebase connection object (or NULL to use config) |
refresh_token |
The refresh token from initial authentication |
api_key |
Firebase API key (used if conn is NULL) |
Response containing new id_token, refresh_token, expires_in, token_type, and user_id
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # Refresh using stored refresh token new_tokens <- auth_refresh_token(conn, old_refresh_token) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # Refresh using stored refresh token new_tokens <- auth_refresh_token(conn, old_refresh_token) }
Sends a password reset email to the specified address.
auth_reset_password(conn = NULL, email, api_key = NULL)auth_reset_password(conn = NULL, email, api_key = NULL)
conn |
Firebase connection object (or NULL to use config) |
email |
User email address |
api_key |
Firebase API key (used if conn is NULL) |
Response indicating success
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { auth_reset_password(conn, "[email protected]") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { auth_reset_password(conn, "[email protected]") }
Authenticates a user with email and password credentials.
auth_sign_in(conn = NULL, email = NULL, password = NULL, api_key = NULL)auth_sign_in(conn = NULL, email = NULL, password = NULL, api_key = NULL)
conn |
Firebase connection object (or NULL to use config) |
email |
User email address |
password |
User password |
api_key |
Firebase API key (used if conn is NULL) |
Authentication response containing idToken, refreshToken, localId, email, and expiresIn
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # With connection object conn <- firebase_connect(project_id = "my-project", api_key = "AIzaSy...") result <- auth_sign_in(conn, "[email protected]", "password123") # Update connection with token conn <- firebase_set_token(conn, result) # Without connection (uses config/environment) result <- auth_sign_in(email = "[email protected]", password = "password123") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # With connection object conn <- firebase_connect(project_id = "my-project", api_key = "AIzaSy...") result <- auth_sign_in(conn, "[email protected]", "password123") # Update connection with token conn <- firebase_set_token(conn, result) # Without connection (uses config/environment) result <- auth_sign_in(email = "[email protected]", password = "password123") }
Updates the display name and/or photo URL of the authenticated user.
auth_update_profile( conn = NULL, display_name = NULL, photo_url = NULL, id_token = NULL, api_key = NULL )auth_update_profile( conn = NULL, display_name = NULL, photo_url = NULL, id_token = NULL, api_key = NULL )
conn |
Firebase connection object with valid token |
display_name |
New display name (or NULL to keep current) |
photo_url |
New photo URL (or NULL to keep current) |
id_token |
ID token (used if conn doesn't have token) |
api_key |
Firebase API key |
Updated user data
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { auth_update_profile(conn, display_name = "John Doe") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { auth_update_profile(conn, display_name = "John Doe") }
Factory function to create a FirebaseToken from an authentication response.
create_token(auth_response, api_key = NULL)create_token(auth_response, api_key = NULL)
auth_response |
Response from Firebase auth API |
api_key |
Firebase API key for token refresh |
A FirebaseToken object
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # After successful authentication response <- auth_sign_in(conn, "[email protected]", "password") token <- create_token(response, api_key = "your-api-key") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # After successful authentication response <- auth_sign_in(conn, "[email protected]", "password") token <- create_token(response, api_key = "your-api-key") }
Legacy user creation. Use auth_create_user() instead.
createUser(projectAPI, email = "prompt", password = "prompt")createUser(projectAPI, email = "prompt", password = "prompt")
projectAPI |
The Firebase Project API key |
email |
User email |
password |
User password |
Registration response
Legacy backup function. Use rtdb_backup() instead.
dataBackup(projectURL, secretKey = "prompt", fileName)dataBackup(projectURL, secretKey = "prompt", fileName)
projectURL |
Firebase database URL |
secretKey |
Admin secret key |
fileName |
Output file name |
File name
Legacy delete function. Use rtdb_delete() instead.
delete(x, projectURL, directory = "main", token = "none")delete(x, projectURL, directory = "main", token = "none")
x |
Data (unused, for signature compatibility) |
projectURL |
Firebase database URL |
directory |
Database path |
token |
Authentication token |
Path
Legacy function. Use storage_delete() instead.
delete_storage( bucket_name, object_name, web_client_id = "prompt", web_client_secret = "prompt" )delete_storage( bucket_name, object_name, web_client_id = "prompt", web_client_secret = "prompt" )
bucket_name |
Storage bucket name |
object_name |
Object name to delete |
web_client_id |
OAuth client ID |
web_client_secret |
OAuth client secret |
NULL on success
Legacy function to deploy R Markdown to storage. Rendering uses a temporary directory for output, intermediate files, and the knitting working directory. Use absolute paths for input resources in the document. Temporary render files are removed after the upload attempt.
deploy_rmarkdown( rmarkdown_path, bucket_name, object_name, web_client_id = "prompt", web_client_secret = "prompt" )deploy_rmarkdown( rmarkdown_path, bucket_name, object_name, web_client_id = "prompt", web_client_secret = "prompt" )
rmarkdown_path |
Path to R Markdown file |
bucket_name |
Storage bucket |
object_name |
Output object name |
web_client_id |
OAuth client ID |
web_client_secret |
OAuth client secret |
Upload result
Legacy download function. Use rtdb_get() instead.
download( projectURL, fileName, secretKey = "none", token = "none", isClass = FALSE )download( projectURL, fileName, secretKey = "none", token = "none", isClass = FALSE )
projectURL |
Firebase database URL |
fileName |
Database path |
secretKey |
Admin secret key |
token |
Authentication token |
isClass |
Whether data is S4 class |
Downloaded data
Legacy interface for the discontinued Firebase Dynamic Links service. Requests to the upstream service no longer succeed.
dynlink_create( conn = NULL, link, domain_uri_prefix, short = TRUE, social_title = NULL, social_description = NULL, social_image_link = NULL, android_package_name = NULL, android_fallback_link = NULL, ios_bundle_id = NULL, ios_fallback_link = NULL, api_key = NULL )dynlink_create( conn = NULL, link, domain_uri_prefix, short = TRUE, social_title = NULL, social_description = NULL, social_image_link = NULL, android_package_name = NULL, android_fallback_link = NULL, ios_bundle_id = NULL, ios_fallback_link = NULL, api_key = NULL )
conn |
Firebase connection object (or NULL to use config) |
link |
The URL you want to shorten/wrap |
domain_uri_prefix |
Your Firebase Dynamic Links domain (e.g., "https://example.page.link") |
short |
Whether to create a short link (TRUE) or unguessable link (FALSE) |
social_title |
Title for social media previews |
social_description |
Description for social media previews |
social_image_link |
Image URL for social media previews |
android_package_name |
Android app package name |
android_fallback_link |
Fallback URL for Android |
ios_bundle_id |
iOS app bundle ID |
ios_fallback_link |
Fallback URL for iOS |
api_key |
Firebase API key (used if conn is NULL) |
This function always raises an error because the upstream service has been shut down.
# The retired service is unavailable; this reports an error without a request. try(dynlink_create( link = "https://example.com/page", domain_uri_prefix = "https://example.page.link" ))# The retired service is unavailable; this reports an error without a request. try(dynlink_create( link = "https://example.com/page", domain_uri_prefix = "https://example.page.link" ))
Clears the connection's authentication state. Note that this doesn't actually close any persistent connections since the REST API is stateless.
firebase_close(conn)firebase_close(conn)
conn |
Firebase connection object |
Updated connection with cleared auth state
Provides configuration loading and management for Firebase settings
Clears session configuration values.
firebase_config_clear(keys = NULL)firebase_config_clear(keys = NULL)
keys |
Specific keys to clear, or NULL to clear all |
Invisibly returns NULL
# Clear specific keys firebase_config_clear(c("api_key", "project_id")) # Clear all firebase_config_clear()# Clear specific keys firebase_config_clear(c("api_key", "project_id")) # Clear all firebase_config_clear()
Retrieves a configuration value using the following priority:
Explicitly passed value
Session configuration (set via firebase_config_set)
Environment variables
Config file (~/.firedata/config.yml or .firedata.yml)
Default value
firebase_config_get(key, value = NULL, default = NULL, profile = "default")firebase_config_get(key, value = NULL, default = NULL, profile = "default")
key |
Configuration key to retrieve |
value |
Explicit value (highest priority) |
default |
Default value if not found |
profile |
Configuration profile (for config file) |
The configuration value or default
# Get API key from environment or config api_key <- firebase_config_get("api_key") # Get with explicit value override api_key <- firebase_config_get("api_key", value = "my-api-key")# Get API key from environment or config api_key <- firebase_config_get("api_key") # Get with explicit value override api_key <- firebase_config_get("api_key", value = "my-api-key")
Loads configuration from a YAML file into session configuration.
firebase_config_load(path = NULL, profile = "default")firebase_config_load(path = NULL, profile = "default")
path |
Path to config file. If NULL, searches in standard locations. |
profile |
Configuration profile to load (default: "default") |
Invisibly returns the loaded configuration
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # Load from default locations firebase_config_load() # Load specific file firebase_config_load("path/to/config.yml") # Load specific profile firebase_config_load(profile = "production") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # Load from default locations firebase_config_load() # Load specific file firebase_config_load("path/to/config.yml") # Load specific profile firebase_config_load(profile = "production") }
Sets configuration values that persist for the current R session.
firebase_config_set(...)firebase_config_set(...)
... |
Named configuration values (project_id, api_key, database_url, storage_bucket) |
Invisibly returns the previous values
firebase_config_set( project_id = "my-project", api_key = "AIzaSy..." ) # Clear the example's session settings when finished firebase_config_clear(c("project_id", "api_key"))firebase_config_set( project_id = "my-project", api_key = "AIzaSy..." ) # Clear the example's session settings when finished firebase_config_clear(c("project_id", "api_key"))
Returns all currently set configuration values from all sources, with
sensitive values masked. Use print() to display the returned list.
firebase_config_show(profile = "default")firebase_config_show(profile = "default")
profile |
Configuration profile for file lookup |
Named list of all configuration values
# View current configuration config <- firebase_config_show() print(config)# View current configuration config <- firebase_config_show() print(config)
Guides the user through setting up Firebase configuration interactively.
firebase_config_wizard(save = FALSE, path = NULL)firebase_config_wizard(save = FALSE, path = NULL)
save |
Whether to offer to save configuration to a file. Defaults to FALSE, which only configures the current session. |
path |
Explicit output file path, required when |
Invisibly returns the configuration list
if (interactive()) { # Run interactive setup firebase_config_wizard() # Optionally save to an explicitly chosen file config_file <- tempfile(fileext = ".yml") firebase_config_wizard(save = TRUE, path = config_file) unlink(config_file) }if (interactive()) { # Run interactive setup firebase_config_wizard() # Optionally save to an explicitly chosen file config_file <- tempfile(fileext = ".yml") firebase_config_wizard(save = TRUE, path = config_file) unlink(config_file) }
Creates a connection object that stores Firebase project configuration and can be passed to various fireData functions. The connection handles configuration resolution from multiple sources (arguments, environment, config files).
firebase_connect( project_id = NULL, api_key = NULL, database_url = NULL, storage_bucket = NULL, credentials = NULL, token = NULL )firebase_connect( project_id = NULL, api_key = NULL, database_url = NULL, storage_bucket = NULL, credentials = NULL, token = NULL )
project_id |
Firebase project ID (e.g., "my-project-12345") |
api_key |
Firebase Web API key |
database_url |
Realtime Database URL. Supply the exact URL shown in the
Firebase console for regional or non-default databases. If NULL, a
US Central default URL is constructed from |
storage_bucket |
Cloud Storage bucket name. If NULL, defaults to the
current |
credentials |
Service account credentials (path to JSON file or ServiceAccountCredentials object) |
token |
User authentication token (FirebaseToken object or token string) |
A firebase_connection S3 object
# Create connection with explicit values conn <- firebase_connect( project_id = "my-project", api_key = "AIzaSy..." ) # Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # These alternatives require your own configuration or credentials. # Create connection from environment variables # (Set FIREBASE_PROJECT_ID, FIREBASE_API_KEY, etc.) conn <- firebase_connect() # Create connection with service account conn <- firebase_connect( project_id = "my-project", credentials = "path/to/service-account.json" ) }# Create connection with explicit values conn <- firebase_connect( project_id = "my-project", api_key = "AIzaSy..." ) # Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # These alternatives require your own configuration or credentials. # Create connection from environment variables # (Set FIREBASE_PROJECT_ID, FIREBASE_API_KEY, etc.) conn <- firebase_connect() # Create connection with service account conn <- firebase_connect( project_id = "my-project", credentials = "path/to/service-account.json" ) }
Provides credential storage, retrieval, and token management
Functions for creating Firebase Dynamic Links (short URLs)
Firebase Dynamic Links shut down on August 25, 2025. These functions are retained for compatibility, but the upstream service no longer creates or serves links. Use another deep-linking provider for new projects.
Functions for interacting with Google Cloud Firestore NoSQL database
Cloud Firestore is a flexible, scalable NoSQL cloud database. Unlike the Realtime Database which stores data as one large JSON tree, Firestore stores data in documents organized into collections.
Collections: Containers for documents (like folders)
Documents: Individual records containing fields (like files)
Fields: Key-value pairs within documents
Subcollections: Collections nested within documents
Firestore requires authentication. Use either:
Service account credentials (recommended for server-side)
User authentication token from auth_sign_in()
Functions for CRUD operations on Firebase Realtime Database
Updates the authentication token on a connection.
firebase_set_token(conn, token)firebase_set_token(conn, token)
conn |
Firebase connection object |
token |
New token (FirebaseToken object or string) |
Updated connection object
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") auth_result <- auth_sign_in(conn, email, password) conn <- firebase_set_token(conn, auth_result) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") auth_result <- auth_sign_in(conn, email, password) conn <- firebase_set_token(conn, auth_result) }
Functions to integrate Firebase authentication with Shiny apps
Functions for file storage operations with Firebase/Google Cloud Storage
Internal utility functions for data conversion and path handling
Represents an authenticated Firebase token with automatic refresh capability.
id_tokenFirebase ID token (JWT)
refresh_tokenRefresh token for obtaining new ID tokens
local_idUser's local ID (UID)
emailUser's email (if available)
expires_atPOSIXct timestamp when the token expires
api_keyFirebase API key (needed for refresh) Create a new FirebaseToken
new()
FirebaseToken$new(auth_response, api_key = NULL)
auth_responseResponse from Firebase auth API
api_keyFirebase API key for token refresh
A new FirebaseToken object Check if token is expired
is_expired()
FirebaseToken$is_expired(buffer_seconds = 300)
buffer_secondsSeconds before actual expiry to consider expired
TRUE if token is expired or will expire within buffer Refresh the token if expired
refresh()
FirebaseToken$refresh(force = FALSE)
forceForce refresh even if not expired
Self (invisibly) Get the current valid token
Automatically refreshes if expired.
get_token()
FirebaseToken$get_token()
The ID token string Print token summary
print()
FirebaseToken$print(...)
...Ignored
clone()
The objects of this class are cloneable with this method.
FirebaseToken$clone(deep = FALSE)
deepWhether to make a deep clone.
Creates a new document with an auto-generated ID.
firestore_add(conn = NULL, collection, data, project_id = NULL, token = NULL)firestore_add(conn = NULL, collection, data, project_id = NULL, token = NULL)
conn |
Firebase connection object |
collection |
Collection path |
data |
List of fields to store |
project_id |
Project ID (uses connection or config if NULL) |
token |
Authentication token (uses connection if NULL) |
The created document data including the generated ID
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # Add document with auto-generated ID result <- firestore_add(conn, "messages", list( text = "Hello, Firestore!", timestamp = Sys.time(), author = "R User" )) # Get the generated document ID print(result$.id) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # Add document with auto-generated ID result <- firestore_add(conn, "messages", list( text = "Hello, Firestore!", timestamp = Sys.time(), author = "R User" )) # Get the generated document ID print(result$.id) }
Deletes a document from Cloud Firestore.
firestore_delete( conn = NULL, collection, document, project_id = NULL, token = NULL )firestore_delete( conn = NULL, collection, document, project_id = NULL, token = NULL )
conn |
Firebase connection object |
collection |
Collection path |
document |
Document ID |
project_id |
Project ID (uses connection or config if NULL) |
token |
Authentication token (uses connection if NULL) |
TRUE if successful
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # Delete a document firestore_delete(conn, "users", "user123") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # Delete a document firestore_delete(conn, "users", "user123") }
Retrieves a single document from Cloud Firestore.
firestore_get( conn = NULL, collection, document, project_id = NULL, token = NULL )firestore_get( conn = NULL, collection, document, project_id = NULL, token = NULL )
conn |
Firebase connection object |
collection |
Collection path (e.g., "users" or "users/uid/posts") |
document |
Document ID |
project_id |
Project ID (uses connection or config if NULL) |
token |
Authentication token (uses connection if NULL) |
Document data as a list, or NULL if not found
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") conn <- firebase_set_token(conn, auth_sign_in(conn, "[email protected]", "password")) # Get a single document user <- firestore_get(conn, "users", "user123") print(user$name) # Get from subcollection post <- firestore_get(conn, "users/user123/posts", "post456") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") conn <- firebase_set_token(conn, auth_sign_in(conn, "[email protected]", "password")) # Get a single document user <- firestore_get(conn, "users", "user123") print(user$name) # Get from subcollection post <- firestore_get(conn, "users/user123/posts", "post456") }
Lists documents in a collection.
firestore_list( conn = NULL, collection, page_size = 100, page_token = NULL, order_by = NULL, project_id = NULL, token = NULL )firestore_list( conn = NULL, collection, page_size = 100, page_token = NULL, order_by = NULL, project_id = NULL, token = NULL )
conn |
Firebase connection object |
collection |
Collection path |
page_size |
Maximum number of documents to return (default 100) |
page_token |
Token for pagination (from previous response) |
order_by |
Field to order by (prefix with "-" for descending) |
project_id |
Project ID (uses connection or config if NULL) |
token |
Authentication token (uses connection if NULL) |
List containing documents and optional nextPageToken
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # List all users (up to 100) result <- firestore_list(conn, "users") for (user in result$documents) { print(user$name) } # Paginate through results result <- firestore_list(conn, "users", page_size = 10) while (!is.null(result$nextPageToken)) { result <- firestore_list(conn, "users", page_size = 10, page_token = result$nextPageToken) } }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # List all users (up to 100) result <- firestore_list(conn, "users") for (user in result$documents) { print(user$name) } # Paginate through results result <- firestore_list(conn, "users", page_size = 10) while (!is.null(result$nextPageToken)) { result <- firestore_list(conn, "users", page_size = 10, page_token = result$nextPageToken) } }
Runs a structured query against a Firestore collection.
firestore_query(conn = NULL, collection, project_id = NULL, token = NULL)firestore_query(conn = NULL, collection, project_id = NULL, token = NULL)
conn |
Firebase connection object |
collection |
Collection path to query |
project_id |
Project ID (uses connection or config if NULL) |
token |
Authentication token (uses connection if NULL) |
A firestore_query object for building the query
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # Query with filters results <- firestore_query(conn, "users") |> fs_where("age", ">=", 18) |> fs_where("active", "==", TRUE) |> fs_order_by("name") |> fs_limit(10) |> fs_execute() }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # Query with filters results <- firestore_query(conn, "users") |> fs_where("age", ">=", 18) |> fs_where("active", "==", TRUE) |> fs_order_by("name") |> fs_limit(10) |> fs_execute() }
Creates or overwrites a document in Cloud Firestore.
firestore_set( conn = NULL, collection, document, data, project_id = NULL, token = NULL )firestore_set( conn = NULL, collection, document, data, project_id = NULL, token = NULL )
conn |
Firebase connection object |
collection |
Collection path |
document |
Document ID |
data |
List of fields to store |
project_id |
Project ID (uses connection or config if NULL) |
token |
Authentication token (uses connection if NULL) |
The created/updated document data
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # Create or overwrite a document firestore_set(conn, "users", "user123", list( name = "John Doe", email = "[email protected]", age = 30, active = TRUE )) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # Create or overwrite a document firestore_set(conn, "users", "user123", list( name = "John Doe", email = "[email protected]", age = 30, active = TRUE )) }
Updates specific fields in a document without overwriting the entire document.
firestore_update( conn = NULL, collection, document, data, project_id = NULL, token = NULL )firestore_update( conn = NULL, collection, document, data, project_id = NULL, token = NULL )
conn |
Firebase connection object |
collection |
Collection path |
document |
Document ID |
data |
List of fields to update |
project_id |
Project ID (uses connection or config if NULL) |
token |
Authentication token (uses connection if NULL) |
The updated document data
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # Update only specific fields firestore_update(conn, "users", "user123", list( lastLogin = Sys.time(), loginCount = 42 )) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project") # Update only specific fields firestore_update(conn, "users", "user123", list( lastLogin = Sys.time(), loginCount = 42 )) }
Executes a Firestore query and returns the results.
fs_execute(query)fs_execute(query)
query |
A firestore_query object |
List of documents matching the query
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { results <- firestore_query(conn, "products") |> fs_where("price", "<", 100) |> fs_order_by("price", "asc") |> fs_limit(20) |> fs_execute() }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { results <- firestore_query(conn, "products") |> fs_where("price", "<", 100) |> fs_order_by("price", "asc") |> fs_limit(20) |> fs_execute() }
Limits the number of documents returned by a query.
fs_limit(query, n)fs_limit(query, n)
query |
A firestore_query object |
n |
Maximum number of documents to return |
Updated firestore_query object
Skips a number of documents before returning results.
fs_offset(query, n)fs_offset(query, n)
query |
A firestore_query object |
n |
Number of documents to skip |
Updated firestore_query object
Adds ordering to a Firestore query.
fs_order_by(query, field, direction = "asc")fs_order_by(query, field, direction = "asc")
query |
A firestore_query object |
field |
Field name to order by |
direction |
Sort direction: "asc" or "desc" |
Updated firestore_query object
Specifies which fields to return in query results.
fs_select(query, ...)fs_select(query, ...)
query |
A firestore_query object |
... |
Field names to select |
Updated firestore_query object
Adds a field filter to a Firestore query.
fs_where(query, field, op, value)fs_where(query, field, op, value)
query |
A firestore_query object |
field |
Field name to filter on |
op |
Comparison operator: "==", "!=", "<", "<=", ">", ">=", "array-contains", "array-contains-any", "in", "not-in" |
value |
Value to compare against |
Updated firestore_query object
conn <- firebase_connect(project_id = "my-project") query <- firestore_query(conn, "users") |> fs_where("age", ">=", 21) |> fs_where("status", "==", "active")conn <- firebase_connect(project_id = "my-project") query <- firestore_query(conn, "users") |> fs_where("age", ">=", 21) |> fs_where("status", "==", "active")
Legacy function. Use dynlink_create() instead.
get_dynamic_link( project_api, domain, link, short = TRUE, social_title = "", social_description = "", social_image_link = "" )get_dynamic_link( project_api, domain, link, short = TRUE, social_title = "", social_description = "", social_image_link = "" )
project_api |
Firebase API key |
domain |
Dynamic Links domain |
link |
URL to shorten |
short |
Whether to create short link |
social_title |
Social preview title |
social_description |
Social preview description |
social_image_link |
Social preview image |
This function always raises an error because the upstream service has been shut down.
Legacy function. Use storage_get_metadata() instead.
get_storage( bucket_name, object_name, web_client_id = "prompt", web_client_secret = "prompt" )get_storage( bucket_name, object_name, web_client_id = "prompt", web_client_secret = "prompt" )
bucket_name |
Storage bucket name |
object_name |
Object name |
web_client_id |
OAuth client ID |
web_client_secret |
OAuth client secret |
Object metadata
Legacy function. Use storage_get_url() instead.
get_url( bucket_name, object_name, web_client_id = "prompt", web_client_secret = "prompt" )get_url( bucket_name, object_name, web_client_id = "prompt", web_client_secret = "prompt" )
bucket_name |
Storage bucket name |
object_name |
Object name |
web_client_id |
OAuth client ID |
web_client_secret |
OAuth client secret |
Download URL
Gets the Firebase token from authenticated user in Shiny context.
get_user_token(user)get_user_token(user)
user |
The reactiveValues object used with shiny_auth_server |
The ID token string or NULL if not authenticated
Legacy function for OAuth token.
google_devstorage_read_only( web_client_id = "prompt", web_client_secret = "prompt" )google_devstorage_read_only( web_client_id = "prompt", web_client_secret = "prompt" )
web_client_id |
OAuth client ID |
web_client_secret |
OAuth client secret |
OAuth token
Legacy function for OAuth token.
google_devstorage_read_write( web_client_id = "prompt", web_client_secret = "prompt" )google_devstorage_read_write( web_client_id = "prompt", web_client_secret = "prompt" )
web_client_id |
OAuth client ID |
web_client_secret |
OAuth client secret |
OAuth token
Legacy function for Firestore OAuth token.
google_firestore( web_client_id = "prompt", web_client_secret = "prompt", cache = FALSE )google_firestore( web_client_id = "prompt", web_client_secret = "prompt", cache = FALSE )
web_client_id |
OAuth client ID |
web_client_secret |
OAuth client secret |
cache |
Whether to cache token |
OAuth token
Legacy Google login. Use auth_google() instead.
google_login( project_api, web_client_id = "prompt", web_client_secret = "prompt", request_uri, redirect_uri = httr::oauth_callback(), return_idp_credential = TRUE, cache = FALSE )google_login( project_api, web_client_id = "prompt", web_client_secret = "prompt", request_uri, redirect_uri = httr::oauth_callback(), return_idp_credential = TRUE, cache = FALSE )
project_api |
Firebase API key |
web_client_id |
Google OAuth client ID |
web_client_secret |
Google OAuth client secret |
request_uri |
Request URI |
redirect_uri |
Redirect URI |
return_idp_credential |
Whether to return IDP credential |
cache |
Whether to cache token |
Authentication response
Helper to check if user is authenticated in Shiny context.
is_authenticated(user)is_authenticated(user)
user |
The reactiveValues object used with shiny_auth_server |
TRUE if user is logged in, FALSE otherwise
Check if Object is a Firebase Connection
is_firebase_connection(x)is_firebase_connection(x)
x |
Object to check |
TRUE if x is a firebase_connection
Legacy function. Use storage_list() instead.
list_storage( bucket_name, web_client_id = "prompt", web_client_secret = "prompt" )list_storage( bucket_name, web_client_id = "prompt", web_client_secret = "prompt" )
bucket_name |
Storage bucket name |
web_client_id |
OAuth client ID |
web_client_secret |
OAuth client secret |
List of objects
Creates ServiceAccountCredentials from a file or environment.
load_service_account(path = NULL)load_service_account(path = NULL)
path |
Path to service account JSON file (optional) |
A ServiceAccountCredentials object
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # From file creds <- load_service_account("path/to/service-account.json") # From GOOGLE_APPLICATION_CREDENTIALS environment variable creds <- load_service_account() }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # From file creds <- load_service_account("path/to/service-account.json") # From GOOGLE_APPLICATION_CREDENTIALS environment variable creds <- load_service_account() }
Legacy OAuth login. Use auth_oauth() instead.
o_auth_login(project_api, request_uri, post_body, return_idp_credential)o_auth_login(project_api, request_uri, post_body, return_idp_credential)
project_api |
Firebase API key |
request_uri |
Request URI |
post_body |
OAuth post body |
return_idp_credential |
Whether to return IDP credential |
Authentication response
Functions to obtain OAuth2 tokens for various Google/Firebase services.
Legacy patch function. Use rtdb_update() instead.
patch(x, projectURL, directory = "main", token = "none")patch(x, projectURL, directory = "main", token = "none")
x |
Data to update |
projectURL |
Firebase database URL |
directory |
Database path |
token |
Authentication token |
Path
Replaces disallowed characters in Firebase paths with hyphens. Firebase paths cannot contain: . $ # [ ] /
[ ]: R:%20
path_sanitize(path) path_check(path)path_sanitize(path) path_check(path)
path |
The database path string |
The sanitized path string
# Path with invalid characters path_sanitize("users/john.doe") # Returns: "users-john-doe" with a warning # Valid path passes through unchanged path_sanitize("users-johndoe") # Returns: "users-johndoe"# Path with invalid characters path_sanitize("users/john.doe") # Returns: "users-john-doe" with a warning # Valid path passes through unchanged path_sanitize("users-johndoe") # Returns: "users-johndoe"
Print Firebase Connection
## S3 method for class 'firebase_connection' print(x, ...)## S3 method for class 'firebase_connection' print(x, ...)
x |
A firebase_connection object |
... |
Additional arguments (ignored) |
Invisibly returns x
Print Firestore Query
## S3 method for class 'firestore_query' print(x, ...)## S3 method for class 'firestore_query' print(x, ...)
x |
A firestore_query object |
... |
Additional arguments (ignored) |
Invisibly returns x
Print Query
## S3 method for class 'rtdb_query' print(x, ...)## S3 method for class 'rtdb_query' print(x, ...)
x |
Query object |
... |
Ignored |
Invisibly returns x
Legacy put function. Use rtdb_set() instead.
put(x, projectURL, directory = "main", token = "none")put(x, projectURL, directory = "main", token = "none")
x |
Data to write |
projectURL |
Firebase database URL |
directory |
Database path |
token |
Authentication token |
Path
End Query at Value
query_end_at(query, value)query_end_at(query, value)
query |
Query builder object |
value |
Ending value (inclusive) |
Updated query builder
Filter Query by Exact Value
query_equal_to(query, value)query_equal_to(query, value)
query |
Query builder object |
value |
Value to match exactly |
Updated query builder
Execute Query
query_execute(query, token = NULL)query_execute(query, token = NULL)
query |
Query builder object |
token |
Authentication token (optional) |
Query results
Limit Query to First N Results
query_limit_to_first(query, n)query_limit_to_first(query, n)
query |
Query builder object |
n |
Number of results |
Updated query builder
Limit Query to Last N Results
query_limit_to_last(query, n)query_limit_to_last(query, n)
query |
Query builder object |
n |
Number of results |
Updated query builder
Order Query by Field
query_order_by(query, field)query_order_by(query, field)
query |
Query builder object |
field |
Field to order by ("$key", "$value", "$priority", or child key) |
Updated query builder
Start Query at Value
query_start_at(query, value)query_start_at(query, value)
query |
Query builder object |
value |
Starting value (inclusive) |
Updated query builder
Legacy password reset. Use auth_reset_password() instead.
resetPassword(projectAPI, email)resetPassword(projectAPI, email)
projectAPI |
The Firebase Project API key |
email |
User email |
Success or warning message
Downloads the entire database to a JSON file.
rtdb_backup(conn, file_name, token = NULL)rtdb_backup(conn, file_name, token = NULL)
conn |
Firebase connection object |
file_name |
Output file path |
token |
Authentication token (typically admin/service account) |
The file name where backup was saved
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect( project_id = "my-project", credentials = "service-account.json" ) backup_file <- tempfile(fileext = ".json") rtdb_backup(conn, backup_file) unlink(backup_file) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect( project_id = "my-project", credentials = "service-account.json" ) backup_file <- tempfile(fileext = ".json") rtdb_backup(conn, backup_file) unlink(backup_file) }
Removes data at the specified path.
rtdb_delete(conn, path, token = NULL)rtdb_delete(conn, path, token = NULL)
conn |
Firebase connection object |
path |
Database path to delete |
token |
Authentication token (overrides connection token) |
The path that was deleted
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Delete user rtdb_delete(conn, "users/user123") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Delete user rtdb_delete(conn, "users/user123") }
Retrieves data from the specified path in the Realtime Database.
rtdb_get(conn, path, shallow = FALSE, is_class = FALSE, token = NULL)rtdb_get(conn, path, shallow = FALSE, is_class = FALSE, token = NULL)
conn |
Firebase connection object |
path |
Database path (e.g., "users/user123") |
shallow |
If TRUE, returns only keys without values (for large datasets) |
is_class |
If TRUE, data is decoded as an S4 class object |
token |
Authentication token (overrides connection token) |
The data at the specified path, or NULL if not found
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Get all users users <- rtdb_get(conn, "users") # Get specific user user <- rtdb_get(conn, "users/user123") # Get only keys (shallow read) keys <- rtdb_get(conn, "users", shallow = TRUE) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Get all users users <- rtdb_get(conn, "users") # Get specific user user <- rtdb_get(conn, "users/user123") # Get only keys (shallow read) keys <- rtdb_get(conn, "users", shallow = TRUE) }
Adds data to a list with an auto-generated unique key.
rtdb_push(conn, path, data, token = NULL)rtdb_push(conn, path, data, token = NULL)
conn |
Firebase connection object |
path |
Database path (parent location) |
data |
Data to push |
token |
Authentication token (overrides connection token) |
The full path including the generated key
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Push new message (auto-generates key) path <- rtdb_push(conn, "messages", list(text = "Hello", timestamp = Sys.time())) # Returns something like "messages/-NxYz..." }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Push new message (auto-generates key) path <- rtdb_push(conn, "messages", list(text = "Hello", timestamp = Sys.time())) # Returns something like "messages/-NxYz..." }
Creates a query builder for filtering and sorting database queries.
rtdb_query(conn, path)rtdb_query(conn, path)
conn |
Firebase connection object |
path |
Database path to query |
A query builder object
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Query users ordered by age, limited to 10 results <- rtdb_query(conn, "users") |> query_order_by("age") |> query_start_at(18) |> query_limit_to_first(10) |> query_execute() }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Query users ordered by age, limited to 10 results <- rtdb_query(conn, "users") |> query_order_by("age") |> query_start_at(18) |> query_limit_to_first(10) |> query_execute() }
Writes data to the specified path, overwriting any existing data. Use rtdb_update() for partial updates.
rtdb_set(conn, path, data, token = NULL)rtdb_set(conn, path, data, token = NULL)
conn |
Firebase connection object |
path |
Database path |
data |
Data to write (data.frame, list, or S4 object) |
token |
Authentication token (overrides connection token) |
The path where data was written
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Set user data rtdb_set(conn, "users/user123", list(name = "John", age = 30)) # Set data frame rtdb_set(conn, "data/mtcars", mtcars) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Set user data rtdb_set(conn, "users/user123", list(name = "John", age = 30)) # Set data frame rtdb_set(conn, "data/mtcars", mtcars) }
Updates specific fields at the specified path without overwriting other existing data. Use rtdb_set() to completely overwrite.
rtdb_update(conn, path, data, token = NULL)rtdb_update(conn, path, data, token = NULL)
conn |
Firebase connection object |
path |
Database path |
data |
Data to update (only specified fields will be changed) |
token |
Authentication token (overrides connection token) |
The path where data was updated
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Update only the age field rtdb_update(conn, "users/user123", list(age = 31)) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", api_key = "...") # Update only the age field rtdb_update(conn, "users/user123", list(age = 31)) }
Creates a login overlay for Shiny applications with support for email/password, Google OAuth, and anonymous authentication.
shiny_auth_server( user, input, output, credentials = TRUE, goauth = TRUE, anonymous = TRUE, project_api = NULL, web_client_id = NULL, web_client_secret = NULL, request_uri = NULL )shiny_auth_server( user, input, output, credentials = TRUE, goauth = TRUE, anonymous = TRUE, project_api = NULL, web_client_id = NULL, web_client_secret = NULL, request_uri = NULL )
user |
A reactiveValues object with a |
input |
Shiny input object |
output |
Shiny output object |
credentials |
Enable email/password login (default: TRUE) |
goauth |
Enable Google OAuth login (default: TRUE) |
anonymous |
Enable anonymous login (default: TRUE) |
project_api |
Firebase API key |
web_client_id |
Google OAuth client ID (required if goauth = TRUE) |
web_client_secret |
Google OAuth client secret (required if goauth = TRUE) |
request_uri |
OAuth redirect URI |
A Shiny UI element containing the login form
if (interactive()) { library(shiny) library(fireData) ui <- fluidPage( shinyjs::useShinyjs(), uiOutput("app") ) server <- function(input, output, session) { USER <- reactiveValues(Logged = FALSE) output$app <- renderUI({ if (!USER$Logged) { shiny_auth_server( user = USER, input = input, output = output, project_api = "your-api-key", web_client_id = "your-client-id", web_client_secret = "your-client-secret", request_uri = "http://localhost" ) } else { # Your main app UI tagList( h1("Welcome!"), actionButton("logout", "Logout") ) } }) } shinyApp(ui, server) }if (interactive()) { library(shiny) library(fireData) ui <- fluidPage( shinyjs::useShinyjs(), uiOutput("app") ) server <- function(input, output, session) { USER <- reactiveValues(Logged = FALSE) output$app <- renderUI({ if (!USER$Logged) { shiny_auth_server( user = USER, input = input, output = output, project_api = "your-api-key", web_client_id = "your-client-id", web_client_secret = "your-client-secret", request_uri = "http://localhost" ) } else { # Your main app UI tagList( h1("Welcome!"), actionButton("logout", "Logout") ) } }) } shinyApp(ui, server) }
Creates a styled login panel for Shiny apps. Use with shiny_auth_server() for complete authentication.
shiny_auth_ui(title = "Sign In")shiny_auth_ui(title = "Sign In")
title |
Title shown on the login panel |
A Shiny UI element
if (interactive()) { ui <- shiny::fluidPage( shinyjs::useShinyjs(), shiny_auth_ui("Sign In") ) }if (interactive()) { ui <- shiny::fluidPage( shinyjs::useShinyjs(), shiny_auth_ui("Sign In") ) }
Deletes a file from Firebase Cloud Storage.
storage_delete(conn, object_name, client_id = NULL, client_secret = NULL)storage_delete(conn, object_name, client_id = NULL, client_secret = NULL)
conn |
Firebase connection object |
object_name |
Name/path of the object to delete |
client_id |
OAuth client ID |
client_secret |
OAuth client secret |
NULL on success
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { storage_delete(conn, "images/old-photo.jpg") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { storage_delete(conn, "images/old-photo.jpg") }
Downloads a file from Firebase Cloud Storage.
storage_download( conn, object_name, dest_file = NULL, client_id = NULL, client_secret = NULL )storage_download( conn, object_name, dest_file = NULL, client_id = NULL, client_secret = NULL )
conn |
Firebase connection object |
object_name |
Name/path of the object in storage |
dest_file |
Local destination path (if NULL, returns content) |
client_id |
OAuth client ID |
client_secret |
OAuth client secret |
If dest_file is NULL, returns file content; otherwise returns dest_file path
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # Download to file dest_file <- tempfile(fileext = ".jpg") storage_download(conn, "images/photo.jpg", dest_file) unlink(dest_file) # Download to memory content <- storage_download(conn, "data/config.json") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # Download to file dest_file <- tempfile(fileext = ".jpg") storage_download(conn, "images/photo.jpg", dest_file) unlink(dest_file) # Download to memory content <- storage_download(conn, "data/config.json") }
Retrieves metadata for a storage object.
storage_get_metadata(conn, object_name, client_id = NULL, client_secret = NULL)storage_get_metadata(conn, object_name, client_id = NULL, client_secret = NULL)
conn |
Firebase connection object |
object_name |
Name/path of the object |
client_id |
OAuth client ID |
client_secret |
OAuth client secret |
Object metadata
Generates a download URL for a storage object.
storage_get_url(conn, object_name, client_id = NULL, client_secret = NULL)storage_get_url(conn, object_name, client_id = NULL, client_secret = NULL)
conn |
Firebase connection object |
object_name |
Name/path of the object |
client_id |
OAuth client ID |
client_secret |
OAuth client secret |
Download URL string
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { url <- storage_get_url(conn, "images/photo.jpg") if (interactive()) { utils::browseURL(url) } }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { url <- storage_get_url(conn, "images/photo.jpg") if (interactive()) { utils::browseURL(url) } }
Lists all files in a storage bucket or prefix.
storage_list( conn, prefix = NULL, delimiter = NULL, max_results = 1000, client_id = NULL, client_secret = NULL )storage_list( conn, prefix = NULL, delimiter = NULL, max_results = 1000, client_id = NULL, client_secret = NULL )
conn |
Firebase connection object |
prefix |
Filter results to objects with this prefix |
delimiter |
Use "/" to list only immediate children |
max_results |
Maximum number of results |
client_id |
OAuth client ID |
client_secret |
OAuth client secret |
List of storage objects
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # List all files files <- storage_list(conn) # List files in a "folder" images <- storage_list(conn, prefix = "images/") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { # List all files files <- storage_list(conn) # List files in a "folder" images <- storage_list(conn, prefix = "images/") }
Uploads a file to Firebase Cloud Storage.
storage_upload( conn, file_path, object_name, content_type = NULL, predefined_acl = NULL, client_id = NULL, client_secret = NULL )storage_upload( conn, file_path, object_name, content_type = NULL, predefined_acl = NULL, client_id = NULL, client_secret = NULL )
conn |
Firebase connection object |
file_path |
Local path to the file to upload |
object_name |
Name/path for the object in storage (e.g., "images/photo.jpg") |
content_type |
MIME type (auto-detected if NULL) |
predefined_acl |
Optional predefined object ACL (for example, "publicRead" or "private"). The default NULL uses bucket IAM and is compatible with uniform bucket-level access. |
client_id |
OAuth client ID (for user auth) |
client_secret |
OAuth client secret (for user auth) |
Storage object metadata including URL
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", storage_bucket = "my-bucket") # Upload with service account result <- storage_upload(conn, "local/photo.jpg", "images/photo.jpg") # Get the public URL print(result$url) }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { conn <- firebase_connect(project_id = "my-project", storage_bucket = "my-bucket") # Upload with service account result <- storage_upload(conn, "local/photo.jpg", "images/photo.jpg") # Get the public URL print(result$url) }
Uploads all files from a local folder to storage.
storage_upload_folder( conn, folder_path, prefix = "", client_id = NULL, client_secret = NULL )storage_upload_folder( conn, folder_path, prefix = "", client_id = NULL, client_secret = NULL )
conn |
Firebase connection object |
folder_path |
Local folder path |
prefix |
Storage prefix/path for uploaded files |
client_id |
OAuth client ID |
client_secret |
OAuth client secret |
List of upload results
# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { results <- storage_upload_folder(conn, "local/images", "images") }# Requires your own Firebase configuration, credentials and example resources. # Adapt the placeholders and set FIREDATA_RUN_EXAMPLES=true to opt in. if (identical(Sys.getenv("FIREDATA_RUN_EXAMPLES"), "true")) { results <- storage_upload_folder(conn, "local/images", "images") }
Legacy upload function. Use rtdb_push() instead.
upload(x, projectURL, directory = "main", token = "none")upload(x, projectURL, directory = "main", token = "none")
x |
Data to upload |
projectURL |
Firebase database URL |
directory |
Database path |
token |
Authentication token |
Path with generated key
Legacy function. Use storage_upload_folder() instead.
upload_folder( bucket_name, web_client_id = "prompt", web_client_secret = "prompt", folder_path )upload_folder( bucket_name, web_client_id = "prompt", web_client_secret = "prompt", folder_path )
bucket_name |
Storage bucket name |
web_client_id |
OAuth client ID |
web_client_secret |
OAuth client secret |
folder_path |
Local folder path |
List of upload results
Legacy function. Use storage_upload() instead.
upload_storage( bucket_name, object_name, web_client_id = "prompt", web_client_secret = "prompt", file_path = NULL, predefined_acl = "publicRead" )upload_storage( bucket_name, object_name, web_client_id = "prompt", web_client_secret = "prompt", file_path = NULL, predefined_acl = "publicRead" )
bucket_name |
Storage bucket name |
object_name |
Object name in storage |
web_client_id |
OAuth client ID |
web_client_secret |
OAuth client secret |
file_path |
Local file path |
predefined_acl |
Access control |
Storage object metadata