Shiny is an R package that makes it easy to build interactive web apps straight from R. You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions. Shiny combines the computational power of R with the interactivity of the modern web.
Using Shiny to share R-based analytics online can bring the core elements of a dashboard from prototyping to production in just a few hours.
The back-end architecture (designed by Will Cowen at Dartmouth)
Data harvesting, analyzing and application deployment
Step 1: harvesting and storing the data
Querying API endpoints and ingest the results to SQL database.
MySQL is a very popular relational database that is similar to SQLite but is more powerful. MySQL databases can either be hosted locally (on the same machine as the Shiny app) or online using a hosting service.
You can use the RMySQL
package to interact with MySQL from R. Since MySQL databases can be hosted on remote servers, the command to connect to the server involves more parameters, but the rest of the saving/loading code is identical to the SQLite approach. To connect to a MySQL database, you need to provide the following parameters: host, port, dbname, user, password.
Setup: You need to create a MySQL database (either locally or using a web service that hosts MySQL databases) and a table that will store the responses.
Step 2: Loading the data
loadData <- function() {
# Connect to the database
db <- dbConnect(MySQL(), dbname = databaseName, host = options()$mysql$host,
port = options()$mysql$port, user = options()$mysql$user,
password = options()$mysql$password)
# Construct the fetching query
query <- sprintf("SELECT * FROM %s", table)
# Submit the fetch query and disconnect
data <- dbGetQuery(db, query)
dbDisconnect(db)
data
}
Step 3: Analyzing and visualizing the data using R
Step 4: Deploying your Shiny app on the web
References:
https://shiny.rstudio.com/articles/persistent-data-storage.html