author: Robert Mitchell | @robertmitchellv date: 2018-12-10 autosize: true css: ../custom.css
incremental: true
- I work at Skid Row Housing Trust as a data analyst
- (I'll just refer to it as SRHT from now on)
- I have been working in this role for around three years
- I am self taught as a programmer/analyst
- Background in philosophy, comp lit, french, information science
incremental: true
- We do three things:
- Develop affordable housing; specifically permanent supportive housing
- Provide supportive services to the residents of our affordable housing projects
- Have an affiliate manage the properties, repairs, et cetera
incremental: true
- We believe in the Housing First model
- We believe in Harm Reduction
- This is pretty much industry standard for the most part
incremental: true
- UI ➡️ server ➡️ user feedback loop
- The different ways your
shiny
app can be interactive - The different ways your
shiny
app can look- The libraries associated with these efforts
- How you can dip your toe into this kind work if phrases like deploy my application are scary using
flexdashboard
instead ofshiny
- Briefly touch on the improvements to the
shiny
framework, e.g.,async
and how you can make it scale (things to think about for later)
incremental: true
- People who have been learning R for a little while and are curious about they can put their work online
- You've maybe done a
shiny
tutorial before but didn't finish it
***T
incremental: true
- You're eager to learn how some of this works but may not have time to put it to use yet
- You're really just dipping your toe into this and want to get an idea into how it works
incremental: true
- It's ok if you walk away from this still not sure how you're going to build your
shiny
application--writing code is hard and you should know it takes non-software engineers a while to wrap their minds around things like this - This is definitely my experience
incremental: true
- The confidence to go home, read through some documentation and just try to start putting things together!
- You won't learn until you try!
incremental: true
![img](../img/rather-use-shiny.jpg)
incremental: true
- You can leverage the work you have already done in R to accomplish something you would normally need to learn JavaScript, Ruby, Python, PHP, or something else to accomplish
- The same way that you would create a visualization for an
rmarkdown
report can be repurposed for another medium- This is especially true of
flexdashboard
, which you should always use in the event ashiny
application is unnecessarily adding complexity to your work! (we'll talk about this more later)
- This is especially true of
incremental: true
- I'm talking about the ways in which your user clicks and explores your dashboard's user interface (UI)
- Which then triggers code in your
server
code to run - Which then returns output back to your input
- So your user can get what they need
incremental: true
The magic behind this is _reactivity_
incremental: false
reactivity
n. reactivity is how we describe the way in which your shiny
application is able to respond to input and update output instantly.
In order for your application to be able to react in this way, it needs to know how to deal with values that will change. We call these reactive values.
incremental: true
- You don't need to know how it works, in order to use it.
- This is actually really good news! It's not meant to feel condescending at all.
- Much better to know how you use reactive values in a
shiny
application for now.
incremental: true
- It's hard to make a slide that can help you understand, so we'll run the following code in our R console
- If you don't have
shiny
installed, then first:
install.packages("shiny")
- Load the library
library(shiny)
- Now run the example
runExample("01_hello")
incremental: true
- If you run:
runExample()
- R will return examples you can explore
runExample
[1] "01_hello" "02_text" "03_reactivity" "04_mpg"
[5] "05_sliders" "06_tabsets" "07_widgets" "08_html"
[9] "09_upload" "10_download" "11_timer"
incremental: true
- Jumping right in to reactivity can make learning
shiny
seem difficult. - Let's start with the basics of the UI
incremental: true
- Since we're talking about dashboards, it makes the most sense to introduce you to the
shinydashboard
package (https://github.com/rstudio/shinydashboard) - A basic
shinydashboard
UI will consist of the following three components- The header
dashboardHeader()
- The sidebar
dashboardSidebar()
- The body
dashboardBody()
- The header
incremental: true
library(shinydashboard)
dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
incremental: true
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
server <- function(input, output) { }
shinyApp(ui, server)
- Believe it or not, this is a complete + functioning
shinydashboard
!
incremental: true
Let's return to some of the examples to see how this works.
incremental: true
- It may seem daunting to figure out how you will serve this dashboard to your users--this can be challenging since there are so many different ways you can approach this.
- However, depending on the consumers of your analysis and their needs you can approach creating dashboards in a slightly different way:
- You can leverage what you've learned about how
shiny
works and employ the same strategies in creating aflexdashboard
, which doesn't require an R server to run! - You can even put it in a share folder and run it in the end user's browser!
- You can leverage what you've learned about how
incremental: true
- Leverage what you already know about
rmarkdown
to create dashboards that you can run without a server - If you don't need to have sliders, or reactive elements; or if this seems like something you don't want to learn, you can just set
shiny
aside to focus onflexdashboard
first - This will help you get more comfortable with developing dashboards.
incremental: true
flexdashboards
can even useshiny
as a runtime, so you can really have the best of both world!
incremental: true
- Rather than rely on
shiny
to do all of the reactive/interactive work, you can also usehtmlwidgets
(https://github.com/ramnathv/htmlwidgets)- What are
htmlwidgets
? plotly
can be anhtmlwidget
leaflet
can be included as anhtmlwidget
- What are
incremental: true
plotly
https://plot.ly/r/leaflet
https://rstudio.github.io/leaflet/
incremental: true
- Since R is a single threaded language (meaning it run one thing at a time), serving your application to thousands of people can be challenging!
- Especially since R is used to do a lot of heavy lifting in connection to statistical modeling/machine learning
shiny
has the ability to now help support these efforts using asynchronous operations
incremental: true
- We're not diving into this, so don't worry!
- I just wanted to let you know that
shiny
is capable and worth learning!
incremental: true
- Basics of
shinydashboard
: https://rstudio.github.io/shinydashboard/get_started.html- These are really great examples--give them a try!
- Deeper dive; this is video 1: https://vimeo.com/131145725
- I would start with this video and go through the material, as it's really well done with great explanations and powerful examples and you don't have to read!
- Reactivy: https://vimeo.com/131147481
- If you don't want to watch all of it, this bit is probably the most important
- Async: https://blog.rstudio.com/2018/06/26/shiny-1-1-0/
- Will cover some history, how to include this into your
shiny
development, and how it all works.
- Will cover some history, how to include this into your
incremental: true
# 🙏 ### ~~Questions?~~