Building powerful dashboards
with R Shiny
Jessica Peterka-Bonetta
July 21, 2016
Shiny and shinydashboard
Shiny: web application framework for R
shinydashboard: makes it easier to use Shiny to build dashboards
·
·
2/13
Shiny
This is how a regular Shiny app looks like:
3/13
Shiny in a nutshell
from the R Studio folks
all within R
can be deployed in the cloud (Shinyapps.io), on-premises (Shiny Server) or
on your own server <- great flexibility
many nice extensions to enhance quality of apps: shinythemes (CSS
themes), shinyjs (JavaScript), hmtlwidgets (JavaScript visualizations),
shinydashboard (Shiny powered dashboards), etc.
can be customized with CSS and Javascript
many many possibilities through: DataTables, widgets, plots, interactive
plots, maps, value boxes, uploads, downloads, etc.
you can reuse your R code
·
·
·
·
·
·
·
4/13
shinydashboard
This is how a shinydashboard looks like:
Earthquakes in Nepal (https://asheshwor.shinyapps.io/np-quake/)
Tweet Analyzer (http://socialdash.adoptitude.com/)
5/13
Components of any Shiny app
UI (ui.R)
server (server.R)
·
·
6/13
I'm reactive. What is your superpower?
7/13
Reactivity for dummies
8/13
In (other) words
"In computing, reactive programming is a programming paradigm oriented
around data flows and the propagation of change. This means that it should
be possible to express static or dynamic data flows with ease in the
programming languages used, and that the underlying execution model will
automatically propagate changes through the data flow."
–Wikipedia
9/13
Reactivity under the hood - UI
ui<-shinyUI(pageWithSidebar(
headerPanel('Irisk-meansclustering'),
sidebarPanel(
selectInput('xcol','XVariable',names(iris)),
selectInput('ycol','YVariable',names(iris),
selected=names(iris)[[2]]),
numericInput('clusters','Clustercount',3,
min=1,max=9)
),
mainPanel(
plotOutput('plot1')
)
))
10/13
Reacitivity under the hood - serverside
server<-shinyServer(function(input,output,session){
output$plot1<-renderPlot({
selectedData<-iris[,c(input$xcol,input$ycol)]
clusters<-kmeans(selectedData(),input$clusters)
par(mar=c(5.1,4.1,0,1))
plot(selectedData,
col=clusters$cluster,
pch=20,cex=3)
points(clusters$centers,pch=4,cex=4,lwd=4)
})
})
11/13
Reacitivity under the hood - modular reactivity
server<-shinyServer(function(input,output,session){
selectedData<-reactive({
iris[,c(input$xcol,input$ycol)]
})
clusters<-reactive({
kmeans(selectedData(),input$clusters)
})
output$plot1<-renderPlot({
par(mar=c(5.1,4.1,0,1))
plot(selectedData(),
col=clusters()$cluster,
pch=20,cex=3)
points(clusters$centers,pch=4,cex=4,lwd=4)
})
})
12/13
Resources
Shiny (http://shiny.rstudio.com/)
shinydashboard (https://rstudio.github.io/shinydashboard/)
Examples (http://www.showmeshiny.com/)
·
·
·
13/13

Building powerful dashboards with r shiny

  • 1.
    Building powerful dashboards withR Shiny Jessica Peterka-Bonetta July 21, 2016
  • 2.
    Shiny and shinydashboard Shiny:web application framework for R shinydashboard: makes it easier to use Shiny to build dashboards · · 2/13
  • 3.
    Shiny This is howa regular Shiny app looks like: 3/13
  • 4.
    Shiny in anutshell from the R Studio folks all within R can be deployed in the cloud (Shinyapps.io), on-premises (Shiny Server) or on your own server <- great flexibility many nice extensions to enhance quality of apps: shinythemes (CSS themes), shinyjs (JavaScript), hmtlwidgets (JavaScript visualizations), shinydashboard (Shiny powered dashboards), etc. can be customized with CSS and Javascript many many possibilities through: DataTables, widgets, plots, interactive plots, maps, value boxes, uploads, downloads, etc. you can reuse your R code · · · · · · · 4/13
  • 5.
    shinydashboard This is howa shinydashboard looks like: Earthquakes in Nepal (https://asheshwor.shinyapps.io/np-quake/) Tweet Analyzer (http://socialdash.adoptitude.com/) 5/13
  • 6.
    Components of anyShiny app UI (ui.R) server (server.R) · · 6/13
  • 7.
    I'm reactive. Whatis your superpower? 7/13
  • 8.
  • 9.
    In (other) words "Incomputing, reactive programming is a programming paradigm oriented around data flows and the propagation of change. This means that it should be possible to express static or dynamic data flows with ease in the programming languages used, and that the underlying execution model will automatically propagate changes through the data flow." –Wikipedia 9/13
  • 10.
    Reactivity under thehood - UI ui<-shinyUI(pageWithSidebar( headerPanel('Irisk-meansclustering'), sidebarPanel( selectInput('xcol','XVariable',names(iris)), selectInput('ycol','YVariable',names(iris), selected=names(iris)[[2]]), numericInput('clusters','Clustercount',3, min=1,max=9) ), mainPanel( plotOutput('plot1') ) )) 10/13
  • 11.
    Reacitivity under thehood - serverside server<-shinyServer(function(input,output,session){ output$plot1<-renderPlot({ selectedData<-iris[,c(input$xcol,input$ycol)] clusters<-kmeans(selectedData(),input$clusters) par(mar=c(5.1,4.1,0,1)) plot(selectedData, col=clusters$cluster, pch=20,cex=3) points(clusters$centers,pch=4,cex=4,lwd=4) }) }) 11/13
  • 12.
    Reacitivity under thehood - modular reactivity server<-shinyServer(function(input,output,session){ selectedData<-reactive({ iris[,c(input$xcol,input$ycol)] }) clusters<-reactive({ kmeans(selectedData(),input$clusters) }) output$plot1<-renderPlot({ par(mar=c(5.1,4.1,0,1)) plot(selectedData(), col=clusters()$cluster, pch=20,cex=3) points(clusters$centers,pch=4,cex=4,lwd=4) }) }) 12/13
  • 13.