Steven Mortimer
March 21, 2017
The shiny package!
Create a folder for your app and put all related files inside that folder. At minimum every Shiny app contains 2 parts:
Take the bare minimum and add the following three items to your folder:
A ui.R
file - holds the client-side logic
A server.R
file - holds the server-side logic
shiny::runGitHub(repo = "com.packtpub.intro.r.bi",
username = "StevenMMortimer",
subdir = "Chapter8-ShinyDashboards/Ch8-BasicShinyApp")
In the ui.R
:
In the server.R
:
Shiny includes a grid-based layout framework based on the Bootstrap project.1
The head tag - The head tag identifies a portion of the web page, usually not visible to the user, which contains the application title, icon, metadata, and scripts.
tags$head(
tags$link(rel = "stylesheet", type = "text/css",
href = "app-styling.css")
)
The progress wheel - Lets the user know that app is processing their input.
shinysky::busyIndicator(text = "Calculation in progress ... ", wait = 0)
Custom JavaScript1 & shinyjs - Extends interactivity and experience
Google Analytics Tracking - Setup an account and Google will give you Javascript snippet to embed to track users.
tags$script("
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-1', 'auto');
ga('send', 'pageview');
")
Connecting to a database - Just like connecting to database from R or RStudio…
library(RPostgreSQL)
con <- dbConnect(dbDriver("PostgreSQL"), dbname = "postgres",
host = "localhost", port = 5432,
user = "user", password = 'password')
app_dat <- dbGetQuery(conn=con, statement="SELECT * FROM app.dat")
dbDisconnect(con)
shinyServer(function(input, output) {
...
The DT package - Highly interactive, functional tables based on
More examples available on https://rstudio.github.io/DT/
Those options explained in more detail here
shiny::runGitHub(repo = "com.packtpub.intro.r.bi",
username = "StevenMMortimer",
subdir = "Chapter8-ShinyDashboards/Ch8-CampaignCreatorApp")
https://reportmort.shinyapps.io/campaign-creator-app/