shiny_db_create {shinymgr} | R Documentation |
Create an empty *shinymgr* SQLite database, and populate with demo data if desired.
Description
Create an empty *shinymgr* SQLite database for managing
multiple apps and scripts in a common framework. This function is
typically not called; instead use shinymgr_setup
Usage
shiny_db_create(db_path, demo)
Arguments
db_path |
Filepath that will house the sqlite database |
demo |
Logical. Should demo data be included? |
Details
The *shinymgr* database is a SQLite database. The function uses
the R package, RSQLite, to connect the database with R (the package
itself contains SQLite, so no external software is needed. Once the
connection is made, the function uses database functions
from the package, DBI, which in turn can be used to query the database,
add records, etc.) This function is not intended to be used.
Rather, users should use shinymgr_setup
to create the
database instance that comes with the package. The function is
included here so users can inspect the code used to create the database.
Value
Returns a *shinymgr* SQLite database.
Tutorials
The shinymgr learnr tutorials include, in order:
-
learnr::run_tutorial(name = "intro", package = "shinymgr")
-
learnr::run_tutorial(name = "shiny", package = "shinymgr")
-
learnr::run_tutorial(name = "modules", package = "shinymgr")
-
learnr::run_tutorial(name = "app_modules", package = "shinymgr")
-
learnr::run_tutorial(name = "tests", package = "shinymgr")
-
learnr::run_tutorial(name = "shinymgr", package = "shinymgr")
-
learnr::run_tutorial(name = "database", package = "shinymgr")
-
learnr::run_tutorial(name = "shinymgr_modules", package = "shinymgr")
-
learnr::run_tutorial(name = "apps", package = "shinymgr")
-
learnr::run_tutorial(name = "analyses", package = "shinymgr")
-
learnr::run_tutorial(name = "reports", package = "shinymgr")
-
learnr::run_tutorial(name = "deployment", package = "shinymgr")
References
https://code.usgs.gov/vtcfwru/shinymgr
See Also
Other database:
shiny_db_populate()
Examples
# ------------------------------------------------------------
# Set up an empty database for demonstration and then delete it
# ------------------------------------------------------------
# create the database (to be deleted):
db_dir <- tempdir()
db_path <- paste0(db_dir, "/shinymgr.sqlite")
shiny_db_create(
db_path = db_path,
demo = TRUE)
# verify that the database exists in your current working directory
file.exists(db_path)
# to work with a database *outside* of a *shinymgr* function,
# load the DBI package first and use RSQLite to set the driver
conx <- DBI::dbConnect(drv = RSQLite::SQLite(), dbname = db_path)
# look at the overall schema
DBI::dbReadTable(conn = conx, "sqlite_master")
# look at the tables in the database
DBI::dbListTables(conx)
# look at fields in table apps
DBI::dbListFields(conx, "apps")
# get more detailed information with a query
DBI::dbGetQuery(conx,
statement = "PRAGMA table_info('apps');"
)
# disconnect from database
DBI::dbDisconnect(conx)
# Delete the test database and remove it from your working directory
unlink(db_path)