Using a SQLite database enables the built-in administration interface, allowing admins to manage users, reset passwords, and view connection logs. The database is encrypted using openssl and passwords are hashed with scrypt.
1. Initialize the database
Use create_db() to create the encrypted SQLite file. You can provide a data.frame of initial credentials. It is recommended to use the keyring package to manage the encryption passphrase securely.
2. Connect the app to the database
Pass the SQLite path and passphrase to check_credentials() within secure_server(). To enable the administration tab in the UI, set enable_admin = TRUE in secure_app().
library(keyring)
# 1. Setup credentials
credentials <- data.frame(
user = c("shiny", "shinymanager"),
password = c("azerty", "12345"),
admin = c(FALSE, TRUE),
stringsAsFactors = FALSE
)
# 2. Secure the passphrase in keyring
key_set("R-shinymanager-key", "your_secret_passphrase")
# 3. Create the database
create_db(
credentials_data = credentials,
sqlite_path = "path/to/database.sqlite",
passphrase = key_get("R-shinymanager-key")
)
# 4. Use in Shiny
ui <- secure_app(ui, enable_admin = TRUE)
server <- function(input, output, session) {
res_auth <- secure_server(
check_credentials = check_credentials(
"path/to/database.sqlite",
passphrase = key_get("R-shinymanager-key")
)
)
# ...
}