Contributed by David Comfort. He took NYC Data Science Academy 12 week full time Data Science Bootcamp program between Sept 23 to Dec 18, 2015. The post was based on his second class project(due at 4th week of the program).
Overall Goal: Build a companion interactive presentation for a book, The Great Escape: Health, Wealth, and the Origins of Inequality, by Nobel Prize-winning economist, Angus Deaton. Specific Goal: Build an interactive presentation with embedded Shiny apps Tools Used: RStudio, Google Charts and GoogleVis
Angus Deaton, winner of the 2015 Nobel Prize in economics, is a Professor of Economics and International Affairs in the Woodrow Wilson School of Public and International Affairs and the Economics Department at Princeton University.
In The Great Escape, Angus Deaton–one of the foremost experts on economic development and on poverty–tells the remarkable story of how, beginning 250 years ago, some parts of the world experienced sustained progress, opening up gaps and setting the stage for today's disproportionately unequal world.
The interactive presentation with the Shiny apps embedded in it, is live at http://216.230.228.88:3838/bootcamp003_student/Project2-Shiny/David....
Figure 2: Create an interactive presentation in R Studio
https://gist.github.com/davidcomfort/7e14540b0dc475357832
ioslides_presentation
output format is specified in the front-matter of the document.css
option. The subdirectory where the css file, style.css
is located is specified as well by www
.keep_md
option.logo
option.transition
option. This can be “default”, “slower”, “faster”, or a numeric value with a number of seconds (e.g. 0.5) .widescreen
option.runtime: shiny
, so you can embed shiny apps into the document. Once you’ve added runtime: shiny
to the document you can run it using either the Run Document command in RStudio or using the rmarkdown::run
function. By default, documents are re-rendered on save, so once you’ve got a browser open with the document loaded, just save the R Markdown file to see your changes.#
and ##
heading tags (you can also create a new slide without a header using a horizontal rule (----
). For example here is the beginning of our slide show:https://gist.github.com/davidcomfort/14eade4ebae65df6db06
shinyApp
function:https://gist.github.com/davidcomfort/d83e2c179b87df93bfcb
echo = FALSE
attribute is used. This is to prevent the R code within the chunk from rendering in the document alongside the Shiny components.I embedded several GoogleVis Motion Charts in my interactive presentation. I went over how I created a GoogleVis motion chart using R and R Markdown in a previous blog post, Gapminder Data Visualization using GoogleVis and R. The specific steps involved were:
googleVis
and shiny
librariesmyChoices
, for the checkboxesrda
file (previously saved) into an R data frame, gapdata
Sub.Region
column of the data frame as a factorhttps://gist.github.com/davidcomfort/a7f59dd3835a98e8cc9b
shinyApp
.ui
.fluidPage
and put the interactive element, the checkboxes, in a sidebar.myChoices
above.myChoices
.motionchart
for simplicity.https://gist.github.com/davidcomfort/da5234b48370b9626a4c
input
object to receive user input from the client web browser. The values in input
are set by UI objects on the client web page.session$clientData.
session$clientData
values, you need to pass a function to shinyServer()
that takes session
as an argument (session
is a special object that is used for finer control over a user’s app session). Once it’s in there, you can access session$clientData
just as you would input
.target_gapdata
"listens" to the client as far as which checkboxes are selected and creates a subset of the data frame based upon which Sub.Regions
a user has selected. It is important that this statement resides outside the output statement below.renderGvis
.target_gapdata <- target_gapdata()
, calls the aforementioned statement to select only the rows for the Sub.Regions
which have been selected by the user.https://gist.github.com/davidcomfort/2f0ab7029c8517566064
GoogleVis
include:data
: a data.frameidvar
: the id variable , “Country” in our case.timevar
: the time variable for the plot, “Years” in our case.xvar
: column name of a numerical vector in data to be plotted on the x-axis.yvar
: column name of a numerical vector in data to be plotted on the y-axis.colorvar
: column name of data that identifies bubbles in the same series. We will use “Region” in our case.sizevar
– values in this column are mapped to actual pixel values using the sizeAxis option. We will use this for “Population”.options=list(state=
statement is used to specify the initial conditions for the chart. This state can be copied from an existing chart by going to advanced settings and copying the state string. (See Figure 3.)Figure 3: Setting State for GoogleVis - See more information about how to create a GoogleVis chart using R at: http://blog.nycdatascience.com/students-work/gapminder-data-visuali....
<img src="www/equation.gif" alt="Happy Planet Index"></img>
https://gist.github.com/davidcomfort/e78cb7ace3d6ded74856 [youtube https://www.youtube.com/watch?v=XwLNqDbPNBw?rel=0&controls=...]
An article can also be embedded using an iframe:
https://gist.github.com/davidcomfort/c424f4dd13e1747bc500 Lessons Learned
The interactive presentation with the Shiny apps embedded in it, is live at http://216.230.228.88:3838/bootcamp003_student/Project2-Shiny/David....
More information about creating interactive presentations using R, R Markdown, Shiny and Knitr can be found at:
Posted 12 April 2021
© 2021 TechTarget, Inc.
Powered by
Badges | Report an Issue | Privacy Policy | Terms of Service
Most Popular Content on DSC
To not miss this type of content in the future, subscribe to our newsletter.
Other popular resources
Archives: 2008-2014 | 2015-2016 | 2017-2019 | Book 1 | Book 2 | More
Most popular articles
You need to be a member of Data Science Central to add comments!
Join Data Science Central