README.md

tasterdb

Tastermonial web apps require a database. These functions help create, load, and maintain the database.

Installation

You can install the developer version of tasterdb from Github with:

devtools::install_github("personalscience/tasterdb",
                        ref = "dev",
                        upgrade = "never")

Example

To load all the Tastermonial database tables for the local configuration:

library(tasterdb)
local_db <- load_db(db_config = "default")

Because the result is an object, it is strongly recommended to assign the function call load_db() to its own variable. This lets you use the various list methods on it, such as

local_db$notes_records # returns a tibble of all notes_records
local_db$disconnect() # disconnect from the database. After this you should `rm(local_db)`

A Sqlite version of the database is also available

sqlite_db <- taster_db(db_config = "sqldb")

Configuration

A directory using this package needs a config.yml file. Be sure to fill in all the values below correctly:

default:
  tastermonial:
    datadir: "~/path/to/a/local/directory/where/you/store/tastermonial/files"
  shiny:
    name: 'personalscience'
    token: 'yourtoken'
    secret: 'your secret'
  dataconnection:
    driver: !expr RPostgres::Postgres()
    host: "localhost"
    user: "postgres"
    password: 'yourlocalpassword'
    port: 5432
    dbname: 'qsdb'
    glucose_table: 'glucose_records'

shinyapps:
  dataconnection:
    driver: !expr RPostgres::Postgres()
    host: "<IP address for local host>"
    user: "username"
    password: 'password'
    port: 5432
    dbname: 'qsdb'
    glucose_table: 'glucose_records'

To run locally, you will need a Postgres database. The app will use the configuration set in the config.yml. To use the local database, run

Sys.setenv(R_CONFIG_ACTIVE = "local")

Database

The app requires a database. Initializing the database is easier if you store all the data in the directory with the path at

config::get("tastermonial")$datadir

This data directory should contain:

Important: The most important function is load_db(). Run this to drop and then load from scratch everything in the current database.

The very first time you set up a new Postgres database, run the function local_db <- taster_db(db_config = "default"). It’s okay to run this as many times as you like; it won’t do anything if the database is already set up properly.

Compile This Readme

You’ll still need to render README.Rmd regularly, to keep README.md up-to-date. devtools::build_readme() is handy for this. You could also use GitHub Actions to re-render README.Rmd every time you push. An example workflow can be found here: https://github.com/r-lib/actions/tree/master/examples.



personalscience/tasterdb documentation built on Dec. 22, 2021, 7:44 a.m.