Interactive data visualization and reporting Dr. etinkaya-Rundel - - PowerPoint PPT Presentation

interactive data visualization and reporting
SMART_READER_LITE
LIVE PREVIEW

Interactive data visualization and reporting Dr. etinkaya-Rundel - - PowerPoint PPT Presentation

Interactive data visualization and reporting Dr. etinkaya-Rundel 2018-04-18 Project tips https://www.youtube.com/watch?v=vGUNqq3jVLg Outline Review Stop-trigger-delay Shiny in Rmd Deploying your app Your turn! Review


slide-1
SLIDE 1

Interactive data visualization and reporting

  • Dr. Çetinkaya-Rundel

2018-04-18

slide-2
SLIDE 2

Project tips

https://www.youtube.com/watch?v=vGUNqq3jVLg

slide-3
SLIDE 3

Outline

  • Review
  • Stop-trigger-delay
  • Shiny in Rmd
  • Deploying your app
  • Your turn!
slide-4
SLIDE 4

Shiny from

Review

slide-5
SLIDE 5

ui <- fluidPage( titlePanel("Multiply by 3"), sidebarLayout( sidebarPanel( sliderInput("x", "Select x", min = 1, max = 50, value = 30) ), mainPanel( textOutput("x_updated") ) ) ) server <- function(input, output) { mult_3 <- function(x) { x * 3 } current_x <- reactive({ mult_3(input$x) })

  • utput$x_updated <- renderText({ current_x })

}

Is there something wrong with this? If so, what? Fix it in review/mult_3.R.

slide-6
SLIDE 6

See review/whats_wrong.R. There are a bunch of small mistakes. See how many you can catch and fix.

slide-7
SLIDE 7

ui <- fluidPage( titlePanel("Multiply by 3"), sidebarLayout( sidebarPanel( sliderInput("x", "Select x", min = 1, max = 50, value = 30) ), mainPanel( textOutput("x_updated") ) ) ) server <- function(input, output) { mult_3 <- function(x) { x * 3 } current_x <- reactive({ mult_3(input$x) })

  • utput$x_updated <- renderText({ current_x })

}

Is there something wrong with this? If so, what? Fix it in review/mult_3.R.

slide-8
SLIDE 8

ui <- fluidPage( titlePanel("Add 2"), sidebarLayout( sidebarPanel( sliderInput("x", "Select x", min = 1, max = 50, value = 30) ), mainPanel( textOutput("x_updated") ) ) ) server <- function(input, output) { add_2 <- function(x) { x + 2 } current_x <- add_2(input$x)

  • utput$x_updated <- renderText({ current_x })

}

Is there something wrong with this? If so, what? Fix it in review/add_2.R.

slide-9
SLIDE 9

Shiny from

Stop - delay - trigger

slide-10
SLIDE 10

Stop with isolate()

  • Wrap an expression with isolate() to suppress its reactivity
  • This will stop the currently executing reactive expression/observer/output

from being notified when the isolated expression changes

slide-11
SLIDE 11

Only update the alpha level when other inputs of the plot change

movies/movies-06.R

slide-12
SLIDE 12

Delay with eventReactive()

  • Calculate a value only in response to a given event with eventReactive()
  • Two main arguments (the event to react to and the value to calculate in response to

this event):

eventReactive(eventExpr, valueExpr, …)

the expression that produces the return value when eventExpr is invalidated simple reactive value - input$click, call to reactive expression - df(),

  • r complex expression inside {}
slide-13
SLIDE 13

Remove the functionality for selecting types, instead randomly sample a user defined number of movies, but only sample and update outputs when an action button is pushed

movies/movies-07.R

slide-14
SLIDE 14

Update the previous app so that a sample with a default sample size is taken and plotted upon launch

movies/movies-08.R

slide-15
SLIDE 15

Trigger with observeEvent()

  • Trigger a reaction (as opposed to calculate/recalculate a value) with observeEvent()
  • Also two main arguments:
  • bserveEvent(eventExpr, handlerExpr, …)

expression to call whenever eventExpr is invalidated simple reactive value - input$click, call to reactive expression - df(),

  • r complex expression inside {}
slide-16
SLIDE 16

Add a button to write a csv

  • f the current random sample

movies/movies-09.R

slide-17
SLIDE 17

Stop-delay-trigger

  • isolate() is used to stop a reaction
  • eventReactive() is used to create a calculated value that only updates in

response to an event

  • observeEvent() is used to perform an action in response to an event
slide-18
SLIDE 18

Shiny from

Shiny in Rmd

slide-19
SLIDE 19

You can embed a Shiny app in an R Markdown file.

movies/movies-10.Rmd

slide-20
SLIDE 20

Shiny from

Deploying your app

slide-21
SLIDE 21

Deploying your app

  • Start with shinyapps.io
  • Easy to use, secure, and scalable
  • Comes with built in metrics
  • Free tier available!
slide-22
SLIDE 22

Shiny from

Your turn!

slide-23
SLIDE 23

Go to our final project on RStudio Cloud. Create a folder called Shiny. In that folder create an R script called app.R. Create a simple data visualization app for using your project. There is no Shiny app requirement for the project, this is just for practice.