SlideShare a Scribd company logo
1 of 35
Download to read offline
1. Importance of data visualisation
2. Understand the structure of a Shiny app
3. Create a Shiny app
2
I
4
http://r4ds.had.co.nz/introduction.html
Import
Wrangle/
Tidy
Explore Transform
Model
Visualise
Communicate
Data visualisation is crucial in various steps of the data
science process
5
• More engaging and better user experience
• Empowers the user
• Telling a story through data
• Easier to understand and remember
• Succinct communication of data
Web application framework for R that helps turn data analyses into interactive web applications
• Open source and big community
• Develop for the web using the same language as for data exploration and modelling
• No HTML, CSS, or JavaScript knowledge required!
• Pre-built widgets, allowing to build elegant and powerful applications with minimal effort
6
7
http://shiny.rstudio.com/gallery/
• Web app: application program stored on a remote server and accessed via a web browser.
8
https://bookdown.org/weicheng/shinyTutorial/web-development.html
Front-end
• Producing HTML, CSS and JavaScript for a
website or web application so that a user
can see and interact with them directly
Back-end
• Creates the logical back-end and core
computational logic of a website
A Shiny app is composed of 2 parts:
ü UI: web document that the user gets to see
ü Server: set of instructions that tell the web page what to show when the user
interacts with the page
9
https://deanattali.com/blog/building-shiny-apps-tutorial/
How does a Shiny app work?
ØThe Server keeps monitoring the UI. Whenever there is a change in the UI, the Server will follow
some instructions (run some R code) accordingly and update the UI (concept of reactivity)
https://shiny.rstudio.com/gallery/movie-explorer.html
• Shiny apps are built around
inputs and outputs
10
1. Layout
• Panels: group elements
together into a single
‘panel’.
• Layouts: organize panels
and elements
11
https://shiny.rstudio.com/reference/shiny/1.0.5/
https://bookdown.org/weicheng/shinyTutorial/ui.html
2. Input
• Create with an *Input() functions
• Adding widgets/inputs
§ Name (id)
§ Label
§ Called using input$name
12
https://shiny.rstudio.com/reference/shiny/1.0.5/
https://bookdown.org/weicheng/shinyTutorial/ui.html
sliderInput(inputId = “myid”, label = “this will show in the UI”, …)
3. Output
• Create with *Output()
functions
• *Output() adds a space in
the ui.R for an R object
13
https://shiny.rstudio.com/reference/shiny/1.0.5/
https://bookdown.org/weicheng/shinyTutorial/ui.html
plotOutput(“histogram”)
• Tells the server how to
render logic using render*()
• Works together with
*output()
14
https://shiny.rstudio.com/reference/shiny/1.0.5/
https://bookdown.org/weicheng/shinyTutorial/ui.html
Output$histogram =
renderPlot({
hist(rnorm(100))
})
15
ShinyServer(function(input, output) {
output$squareNum = renderText({
paste("The square of your number is: ",
input$numInput^2)
})
})
ShinyUI(fluidPage(
titlePanel("Dummy app"),
mainPanel(
numericInput(id = "numInput", label = "A numeric input:",
value = 7, min = 1, max = 30),
textOutput("squareNum")
)
))
Watch out for ,, ( ) { }
When your component is as an argument to a function, you should use ,,
otherwise don’t!
Use ,, inside a fluidRow. Don’t use ,, to separate elements in server.R file.
Reactivity is what enables your outputs to react to changes in inputs. If x is a reactive variable, this
means that when the value of a variable x changes, then anything that relies on x gets re-evaluated
• In Shiny all inputs are automatically reactive.
• Reactive variables can only be used inside reactive contexts. Any render* function is a reactive
context
• Besides render*(), there are other 2 common reactive contexts: reactive({ }) and observe({ })
16
http://rstudio.github.io/shiny/tutorial/#reactivity
https://deanattali.com/blog/building-shiny-apps-tutorial/#10-reactivity-101
Whenever you want to print a reactive
variable for debug you need to
remember to wrap it in an observe({ }):
observe({ print(input$x )})
• Modularize code with reactive()
• Reactive expression
1. Call a reactive expression like a function. ex. data()
2. Reactive expression cache their values to avoid unnecessary computation
17
http://rstudio.github.io/shiny/tutorial/#reactivity
https://deanattali.com/blog/building-shiny-apps-tutorial/#10-reactivity-101
input$numInput
data = reactive({
rnorm(input$numInput)
})
output$hist =
renderPlot({
hist(data())
})
output$stats =
renderPrint({
summary(data())
})
18
• Create some inputs
• Create a space for output
• Choose a reactive function that will
accept our input
• Assign the reactive function to an output
that will update the user interface
• shinyapps.io – a server maintained by Rstudio
http://docs.rstudio.com/shinyapps.io/getting-started.html
• Shiny Server – build your own server
https://shiny.rstudio.com/articles/shiny-server.html
• Docker container – deploy and share anywhere
(wait for one of our next workshops to know learn more about docker!)
19
II
Repo available here: https://github.com/amguedes/ShinySeminar
• Create a Shiny app to visualise the 500 best albums of all time by Rolling Stone
21
https://www.kaggle.com/notgibs/500-greatest-albums-of-all-time-rolling-stone
What do we want to know?
ü What’s the best artist of all time? And in a specific date interval?
ü Which years/artists were more prolific in best albums?
ü How has genre/artist popularity evolved along time?
3. Create an empty Shiny app
3.1 File à New à Shiny Web App à Multiple File
3.2 Run the app
1. Open RStudio
2.install.packages("shiny")
library(shiny)
22
23
Myapp
<folder, directory path>
ui.R
global.R
Somedata.csv
server.R
• There are 2 different ways to organize your shiny app (single file vs multiple files)
• We will be using the following:
ui.R and server.R need to
have that exact name
24
Repo available here: https://github.com/royalmail-datascience/Meetup1_DataVisualisationShiny.git
25
• This file is read before launching the app
→ After launching the app, both the ui.R and server.R will have access to all objects and any of
the global variables that were defined
→ global.R needs to be sourced in ui.R and server.R
DEMO
>
Navbar page title
Tab panel title
sliderInput
Radio buttons
Main panel
plotOutput
dataTableOutput
textOutput
Sidebar panel
27
• Layout
• Input
• Output
sliderInput(inputId = “myid”,
label = “this will show in the
UI”, …)
plotOutput(“histogram”)
DEMO
>
28
DEMO
>
• Render output
• Data manipulation
Tab panel title
sliderInput
Action button
Main panel
plotOutput
dataTableOutput
Sidebar panel
Tab panel title
Tabset panels Main panel
plotOutput
• http://rstudio.github.io/shinythemes/
• http://rstudio.github.io/leaflet/shiny.html
• http://shiny.rstudio.com/reference/shiny/1.1.0/
• https://github.com/rstudio/shiny-examples
• https://rstudio.github.io/shinydashboard/
• https://shiny.rstudio.com/tutorial/
• http://rstudio.github.io/shiny/tutorial/
• http://shiny.rstudio.com/articles/html-tags.html
• https://shiny.rstudio.com/images/shiny-cheatsheet.pdf
• https://shiny.rstudio.com/articles/layout-guide.html
• https://shiny.rstudio.com/gallery/
• https://www.showmeshiny.com/
31
• https://plot.ly/r/shiny-gallery/
• https://shinyapps-recent.appspot.com/recent.html
• https://deanattali.com/blog/building-shiny-apps-tutorial/
• https://bookdown.org/weicheng/shinyTutorial/resources.html
• http://stcorp.nl/R_course/tutorial_shiny.html
• http://zevross.com/blog/2016/04/19/r-powered-web-applications-
with-shiny-a-tutorial-and-cheat-sheet-with-40-example-apps/
• https://www.rstudio.com/resources/webinars/shiny-developer-
conference/
III
Repo available here: https://github.com/amguedes/ShinySeminar
33
• Now that you have your shiny app up and running try to play with it by doing the following tasks (solutions
can be found in the repository)
1. Add the Year option on “Home” panel à X-axis (and update the plot accordingly)
2. Add two new tabsets on “Time series analysis” for Artist and Artist evolution (use Genre tabs as
templates)
34
1. Add the Year option on “Home” panel à X-axis (and update the plot accordingly)
35
2. Add two new tabs on “Time series analysis” for Artist and Artist evolution (use Genre tabs as
templates)

More Related Content

What's hot

PySpark Best Practices
PySpark Best PracticesPySpark Best Practices
PySpark Best PracticesCloudera, Inc.
 
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...Databricks
 
Real-time Analytics with Apache Flink and Druid
Real-time Analytics with Apache Flink and DruidReal-time Analytics with Apache Flink and Druid
Real-time Analytics with Apache Flink and DruidJan Graßegger
 
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...Databricks
 
Real-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache PinotReal-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache PinotXiang Fu
 
A la découverte du Web sémantique
A la découverte du Web sémantiqueA la découverte du Web sémantique
A la découverte du Web sémantiqueGautier Poupeau
 
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3Migrating your clusters and workloads from Hadoop 2 to Hadoop 3
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3DataWorks Summit
 
Linking the world with Python and Semantics
Linking the world with Python and SemanticsLinking the world with Python and Semantics
Linking the world with Python and SemanticsTatiana Al-Chueyr
 
Mongo DB schema design patterns
Mongo DB schema design patternsMongo DB schema design patterns
Mongo DB schema design patternsjoergreichert
 
Introduction to spark
Introduction to sparkIntroduction to spark
Introduction to sparkDuyhai Doan
 
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...Databricks
 
Introduction to hadoop and hdfs
Introduction to hadoop and hdfsIntroduction to hadoop and hdfs
Introduction to hadoop and hdfsshrey mehrotra
 
Introduction to Apache Flink
Introduction to Apache FlinkIntroduction to Apache Flink
Introduction to Apache Flinkmxmxm
 
Bubbles – Virtual Data Objects
Bubbles – Virtual Data ObjectsBubbles – Virtual Data Objects
Bubbles – Virtual Data ObjectsStefan Urbanek
 

What's hot (20)

Graph database
Graph database Graph database
Graph database
 
PySpark Best Practices
PySpark Best PracticesPySpark Best Practices
PySpark Best Practices
 
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...
CERN’s Next Generation Data Analysis Platform with Apache Spark with Enric Te...
 
Real-time Analytics with Apache Flink and Druid
Real-time Analytics with Apache Flink and DruidReal-time Analytics with Apache Flink and Druid
Real-time Analytics with Apache Flink and Druid
 
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...
 
Real-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache PinotReal-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache Pinot
 
A la découverte du Web sémantique
A la découverte du Web sémantiqueA la découverte du Web sémantique
A la découverte du Web sémantique
 
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3Migrating your clusters and workloads from Hadoop 2 to Hadoop 3
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3
 
Linking the world with Python and Semantics
Linking the world with Python and SemanticsLinking the world with Python and Semantics
Linking the world with Python and Semantics
 
Mongo DB schema design patterns
Mongo DB schema design patternsMongo DB schema design patterns
Mongo DB schema design patterns
 
Introduction to spark
Introduction to sparkIntroduction to spark
Introduction to spark
 
Introduction to Celery
Introduction to CeleryIntroduction to Celery
Introduction to Celery
 
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
 
Introduction to hadoop and hdfs
Introduction to hadoop and hdfsIntroduction to hadoop and hdfs
Introduction to hadoop and hdfs
 
Map Reduce
Map ReduceMap Reduce
Map Reduce
 
Spark SQL
Spark SQLSpark SQL
Spark SQL
 
Graph databases
Graph databasesGraph databases
Graph databases
 
Spark etl
Spark etlSpark etl
Spark etl
 
Introduction to Apache Flink
Introduction to Apache FlinkIntroduction to Apache Flink
Introduction to Apache Flink
 
Bubbles – Virtual Data Objects
Bubbles – Virtual Data ObjectsBubbles – Virtual Data Objects
Bubbles – Virtual Data Objects
 

Similar to Introduction to interactive data visualisation using R Shiny

Titanium appcelerator my first app
Titanium appcelerator my first appTitanium appcelerator my first app
Titanium appcelerator my first appAlessio Ricco
 
A intro to (hosted) Shiny Apps
A intro to (hosted) Shiny AppsA intro to (hosted) Shiny Apps
A intro to (hosted) Shiny AppsDaniel Koller
 
Introduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in RIntroduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in RPaul Richards
 
Building interactive web app with shiny
Building interactive web app with shinyBuilding interactive web app with shiny
Building interactive web app with shinyVivian S. Zhang
 
Android Applications Development: A Quick Start Guide
Android Applications Development: A Quick Start GuideAndroid Applications Development: A Quick Start Guide
Android Applications Development: A Quick Start GuideSergii Zhuk
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React NativeEric Deng
 
The fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactThe fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactOliver N
 
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break editionMatteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break editionDuckMa
 
Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...
Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...
Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...InfluxData
 
Getting started with titanium
Getting started with titaniumGetting started with titanium
Getting started with titaniumNaga Harish M
 
Let's build Developer Portal with Backstage
Let's build Developer Portal with BackstageLet's build Developer Portal with Backstage
Let's build Developer Portal with BackstageOpsta
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroMohammad Shaker
 
Engineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) DevelopmentEngineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) DevelopmentLiving Online
 
Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017Melania Andrisan (Danciu)
 
Getting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumGetting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumTechday7
 
Matteo Gazzurelli - Andorid introduction - Google Dev Fest 2013
Matteo Gazzurelli - Andorid introduction - Google Dev Fest 2013Matteo Gazzurelli - Andorid introduction - Google Dev Fest 2013
Matteo Gazzurelli - Andorid introduction - Google Dev Fest 2013DuckMa
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom componentsJeremy Grancher
 
project_proposal_osrf
project_proposal_osrfproject_proposal_osrf
project_proposal_osrfom1234567890
 

Similar to Introduction to interactive data visualisation using R Shiny (20)

Build web apps with R
Build web apps with RBuild web apps with R
Build web apps with R
 
Titanium appcelerator my first app
Titanium appcelerator my first appTitanium appcelerator my first app
Titanium appcelerator my first app
 
A intro to (hosted) Shiny Apps
A intro to (hosted) Shiny AppsA intro to (hosted) Shiny Apps
A intro to (hosted) Shiny Apps
 
shiny.pdf
shiny.pdfshiny.pdf
shiny.pdf
 
Introduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in RIntroduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in R
 
Building interactive web app with shiny
Building interactive web app with shinyBuilding interactive web app with shiny
Building interactive web app with shiny
 
Android Applications Development: A Quick Start Guide
Android Applications Development: A Quick Start GuideAndroid Applications Development: A Quick Start Guide
Android Applications Development: A Quick Start Guide
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
 
The fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactThe fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose React
 
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break editionMatteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
 
Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...
Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...
Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...
 
Getting started with titanium
Getting started with titaniumGetting started with titanium
Getting started with titanium
 
Let's build Developer Portal with Backstage
Let's build Developer Portal with BackstageLet's build Developer Portal with Backstage
Let's build Developer Portal with Backstage
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - Intro
 
Engineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) DevelopmentEngineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) Development
 
Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017
 
Getting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumGetting started with Appcelerator Titanium
Getting started with Appcelerator Titanium
 
Matteo Gazzurelli - Andorid introduction - Google Dev Fest 2013
Matteo Gazzurelli - Andorid introduction - Google Dev Fest 2013Matteo Gazzurelli - Andorid introduction - Google Dev Fest 2013
Matteo Gazzurelli - Andorid introduction - Google Dev Fest 2013
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
 
project_proposal_osrf
project_proposal_osrfproject_proposal_osrf
project_proposal_osrf
 

Recently uploaded

VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home ServiceSapana Sha
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAmazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAbdelrhman abooda
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Cantervoginip
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Jack DiGiovanna
 

Recently uploaded (20)

VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAmazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Canter
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
 

Introduction to interactive data visualisation using R Shiny

  • 1.
  • 2. 1. Importance of data visualisation 2. Understand the structure of a Shiny app 3. Create a Shiny app 2
  • 3. I
  • 5. 5 • More engaging and better user experience • Empowers the user • Telling a story through data • Easier to understand and remember • Succinct communication of data
  • 6. Web application framework for R that helps turn data analyses into interactive web applications • Open source and big community • Develop for the web using the same language as for data exploration and modelling • No HTML, CSS, or JavaScript knowledge required! • Pre-built widgets, allowing to build elegant and powerful applications with minimal effort 6
  • 8. • Web app: application program stored on a remote server and accessed via a web browser. 8 https://bookdown.org/weicheng/shinyTutorial/web-development.html Front-end • Producing HTML, CSS and JavaScript for a website or web application so that a user can see and interact with them directly Back-end • Creates the logical back-end and core computational logic of a website
  • 9. A Shiny app is composed of 2 parts: ü UI: web document that the user gets to see ü Server: set of instructions that tell the web page what to show when the user interacts with the page 9 https://deanattali.com/blog/building-shiny-apps-tutorial/ How does a Shiny app work? ØThe Server keeps monitoring the UI. Whenever there is a change in the UI, the Server will follow some instructions (run some R code) accordingly and update the UI (concept of reactivity)
  • 11. 1. Layout • Panels: group elements together into a single ‘panel’. • Layouts: organize panels and elements 11 https://shiny.rstudio.com/reference/shiny/1.0.5/ https://bookdown.org/weicheng/shinyTutorial/ui.html
  • 12. 2. Input • Create with an *Input() functions • Adding widgets/inputs § Name (id) § Label § Called using input$name 12 https://shiny.rstudio.com/reference/shiny/1.0.5/ https://bookdown.org/weicheng/shinyTutorial/ui.html sliderInput(inputId = “myid”, label = “this will show in the UI”, …)
  • 13. 3. Output • Create with *Output() functions • *Output() adds a space in the ui.R for an R object 13 https://shiny.rstudio.com/reference/shiny/1.0.5/ https://bookdown.org/weicheng/shinyTutorial/ui.html plotOutput(“histogram”)
  • 14. • Tells the server how to render logic using render*() • Works together with *output() 14 https://shiny.rstudio.com/reference/shiny/1.0.5/ https://bookdown.org/weicheng/shinyTutorial/ui.html Output$histogram = renderPlot({ hist(rnorm(100)) })
  • 15. 15 ShinyServer(function(input, output) { output$squareNum = renderText({ paste("The square of your number is: ", input$numInput^2) }) }) ShinyUI(fluidPage( titlePanel("Dummy app"), mainPanel( numericInput(id = "numInput", label = "A numeric input:", value = 7, min = 1, max = 30), textOutput("squareNum") ) )) Watch out for ,, ( ) { } When your component is as an argument to a function, you should use ,, otherwise don’t! Use ,, inside a fluidRow. Don’t use ,, to separate elements in server.R file.
  • 16. Reactivity is what enables your outputs to react to changes in inputs. If x is a reactive variable, this means that when the value of a variable x changes, then anything that relies on x gets re-evaluated • In Shiny all inputs are automatically reactive. • Reactive variables can only be used inside reactive contexts. Any render* function is a reactive context • Besides render*(), there are other 2 common reactive contexts: reactive({ }) and observe({ }) 16 http://rstudio.github.io/shiny/tutorial/#reactivity https://deanattali.com/blog/building-shiny-apps-tutorial/#10-reactivity-101 Whenever you want to print a reactive variable for debug you need to remember to wrap it in an observe({ }): observe({ print(input$x )})
  • 17. • Modularize code with reactive() • Reactive expression 1. Call a reactive expression like a function. ex. data() 2. Reactive expression cache their values to avoid unnecessary computation 17 http://rstudio.github.io/shiny/tutorial/#reactivity https://deanattali.com/blog/building-shiny-apps-tutorial/#10-reactivity-101 input$numInput data = reactive({ rnorm(input$numInput) }) output$hist = renderPlot({ hist(data()) }) output$stats = renderPrint({ summary(data()) })
  • 18. 18 • Create some inputs • Create a space for output • Choose a reactive function that will accept our input • Assign the reactive function to an output that will update the user interface
  • 19. • shinyapps.io – a server maintained by Rstudio http://docs.rstudio.com/shinyapps.io/getting-started.html • Shiny Server – build your own server https://shiny.rstudio.com/articles/shiny-server.html • Docker container – deploy and share anywhere (wait for one of our next workshops to know learn more about docker!) 19
  • 20. II Repo available here: https://github.com/amguedes/ShinySeminar
  • 21. • Create a Shiny app to visualise the 500 best albums of all time by Rolling Stone 21 https://www.kaggle.com/notgibs/500-greatest-albums-of-all-time-rolling-stone What do we want to know? ü What’s the best artist of all time? And in a specific date interval? ü Which years/artists were more prolific in best albums? ü How has genre/artist popularity evolved along time?
  • 22. 3. Create an empty Shiny app 3.1 File à New à Shiny Web App à Multiple File 3.2 Run the app 1. Open RStudio 2.install.packages("shiny") library(shiny) 22
  • 23. 23 Myapp <folder, directory path> ui.R global.R Somedata.csv server.R • There are 2 different ways to organize your shiny app (single file vs multiple files) • We will be using the following: ui.R and server.R need to have that exact name
  • 24. 24 Repo available here: https://github.com/royalmail-datascience/Meetup1_DataVisualisationShiny.git
  • 25. 25 • This file is read before launching the app → After launching the app, both the ui.R and server.R will have access to all objects and any of the global variables that were defined → global.R needs to be sourced in ui.R and server.R DEMO >
  • 26. Navbar page title Tab panel title sliderInput Radio buttons Main panel plotOutput dataTableOutput textOutput Sidebar panel
  • 27. 27 • Layout • Input • Output sliderInput(inputId = “myid”, label = “this will show in the UI”, …) plotOutput(“histogram”) DEMO >
  • 28. 28 DEMO > • Render output • Data manipulation
  • 29. Tab panel title sliderInput Action button Main panel plotOutput dataTableOutput Sidebar panel
  • 30. Tab panel title Tabset panels Main panel plotOutput
  • 31. • http://rstudio.github.io/shinythemes/ • http://rstudio.github.io/leaflet/shiny.html • http://shiny.rstudio.com/reference/shiny/1.1.0/ • https://github.com/rstudio/shiny-examples • https://rstudio.github.io/shinydashboard/ • https://shiny.rstudio.com/tutorial/ • http://rstudio.github.io/shiny/tutorial/ • http://shiny.rstudio.com/articles/html-tags.html • https://shiny.rstudio.com/images/shiny-cheatsheet.pdf • https://shiny.rstudio.com/articles/layout-guide.html • https://shiny.rstudio.com/gallery/ • https://www.showmeshiny.com/ 31 • https://plot.ly/r/shiny-gallery/ • https://shinyapps-recent.appspot.com/recent.html • https://deanattali.com/blog/building-shiny-apps-tutorial/ • https://bookdown.org/weicheng/shinyTutorial/resources.html • http://stcorp.nl/R_course/tutorial_shiny.html • http://zevross.com/blog/2016/04/19/r-powered-web-applications- with-shiny-a-tutorial-and-cheat-sheet-with-40-example-apps/ • https://www.rstudio.com/resources/webinars/shiny-developer- conference/
  • 32. III Repo available here: https://github.com/amguedes/ShinySeminar
  • 33. 33 • Now that you have your shiny app up and running try to play with it by doing the following tasks (solutions can be found in the repository) 1. Add the Year option on “Home” panel à X-axis (and update the plot accordingly) 2. Add two new tabsets on “Time series analysis” for Artist and Artist evolution (use Genre tabs as templates)
  • 34. 34 1. Add the Year option on “Home” panel à X-axis (and update the plot accordingly)
  • 35. 35 2. Add two new tabs on “Time series analysis” for Artist and Artist evolution (use Genre tabs as templates)