Build an Alien Sightings Dashboard BUILDIN G W EB AP P LICATION S - - PowerPoint PPT Presentation

build an alien sightings dashboard
SMART_READER_LITE
LIVE PREVIEW

Build an Alien Sightings Dashboard BUILDIN G W EB AP P LICATION S - - PowerPoint PPT Presentation

Build an Alien Sightings Dashboard BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R Kaelen Medeiros Data Scientist Alien Sightings Dashboard BUILDING WEB APPLICATIONS WITH SHINY IN R Choices, choices... ui <- fluidPage(


slide-1
SLIDE 1

Build an Alien Sightings Dashboard

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

Kaelen Medeiros

Data Scientist

slide-2
SLIDE 2

BUILDING WEB APPLICATIONS WITH SHINY IN R

Alien Sightings Dashboard

slide-3
SLIDE 3

BUILDING WEB APPLICATIONS WITH SHINY IN R

Choices, choices...

ui <- fluidPage( selectInput("shape", "Choose a shape:", choices = unique(usa_ufo_sightings$shape) ) )

slide-4
SLIDE 4

BUILDING WEB APPLICATIONS WITH SHINY IN R

Alien Sightings Dashboard, tab 2

slide-5
SLIDE 5

Let's practice!

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

slide-6
SLIDE 6

Exploring the 2014 Mental Health in Tech Survey

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

Kaelen Medeiros

Data Scientist

slide-7
SLIDE 7

BUILDING WEB APPLICATIONS WITH SHINY IN R

2014 Mental Health in Tech Survey

Administered by Open Sourcing Mental Illness (OSMI), a non-prot OMSI website with survey: https://osmihelp.org/research Filter for Age > 0 Inputs are questions about mental health consequences and mental vs. physical health

slide-8
SLIDE 8

BUILDING WEB APPLICATIONS WITH SHINY IN R

2014 Mental Health in Tech Survey app

slide-9
SLIDE 9

BUILDING WEB APPLICATIONS WITH SHINY IN R

Custom error messages

server <- function(input, output, session) {

  • utput$age <- renderTable({

validate( need(input$age != "", "Be sure to select an age.") ) mental_health_survey %>% summarize(avg_age = mean(Age)) }) }

slide-10
SLIDE 10

BUILDING WEB APPLICATIONS WITH SHINY IN R

Custom error messages

slide-11
SLIDE 11

BUILDING WEB APPLICATIONS WITH SHINY IN R

shinyWidgets

shinyWidgetsGallery()

slide-12
SLIDE 12

Let's practice!

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

slide-13
SLIDE 13

Explore cuisines

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

Ramnath Vaidyanathan

VP of Product Research

slide-14
SLIDE 14

BUILDING WEB APPLICATIONS WITH SHINY IN R

Explore data

slide-15
SLIDE 15

BUILDING WEB APPLICATIONS WITH SHINY IN R

slide-16
SLIDE 16

BUILDING WEB APPLICATIONS WITH SHINY IN R

ui <- fluidPage( titlePanel('Explore Cuisines'), sidebarLayout( sidebarPanel( selectInput('cuisine', 'Select Cuisine', unique(recipes$cuisine)), sliderInput('nb_ingredients', 'Select No. of Ingredients', 5, 100, 20), ), mainPanel( tabsetPanel( tabPanel('Word Cloud', d3wordcloudOutput('wc_ingredients')), tabPanel('Plot', plotly::plotlyOutput('plot_top_ingredients')), tabPanel('Table', DT::DTOutput('dt_top_ingredients')) ) ) ) )

slide-17
SLIDE 17

BUILDING WEB APPLICATIONS WITH SHINY IN R

slide-18
SLIDE 18

BUILDING WEB APPLICATIONS WITH SHINY IN R

Add output: interactive table

  • utput$dt_top_ingredients <- DT::renderDT({

recipes %>% filter(cuisine == input$cuisine) %>% count(ingredient, name = 'nb_recipes') %>% arrange(desc(nb_recipes)) %>% head(input$nb_ingredients) })

slide-19
SLIDE 19

BUILDING WEB APPLICATIONS WITH SHINY IN R

Compute TFIDF

recipes_enriched <- recipes %>% count(cuisine, ingredient, name = 'nb_recipes') %>% tidytext::bind_tf_idf(ingredient, cuisine, nb_recipes)

slide-20
SLIDE 20

BUILDING WEB APPLICATIONS WITH SHINY IN R

Add a reactive expression

rval_top_ingredients <- reactive({ recipes_enriched %>% filter(cuisine == input$cuisine) %>% arrange(desc(tf_idf)) %>% head(input$nb_ingredients) %>% mutate(ingredient = forcats::fct_reorder(ingredient, tf_idf)) })

slide-21
SLIDE 21

BUILDING WEB APPLICATIONS WITH SHINY IN R

Add outputs: interactive plot and word cloud

  • utput$plot_top_ingredients <- plotly::renderPlotly({

rval_top_ingredients() %>% ggplot(aes(x = ingredient, y = tf_idf)) + geom_col() + coord_flip() })

  • utput$wc_ingredients <- d3wordcloud::renderD3wordcloud({

d <- rval_top_ingredients() d3wordcloud(d$ingredient, d$nb_recipes, tooltip = TRUE) })

slide-22
SLIDE 22

BUILDING WEB APPLICATIONS WITH SHINY IN R

slide-23
SLIDE 23

Let's practice!

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

slide-24
SLIDE 24

Mass shootings

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

Ramnath Vaidyanathan

VP of Product Research

slide-25
SLIDE 25

BUILDING WEB APPLICATIONS WITH SHINY IN R

Explore data

slide-26
SLIDE 26

BUILDING WEB APPLICATIONS WITH SHINY IN R

slide-27
SLIDE 27

BUILDING WEB APPLICATIONS WITH SHINY IN R

Add UI

ui <- bootstrapPage( theme = shinythemes::shinytheme('simplex'), leaflet::leafletOutput('map', width = '100%', height = '100%'), absolutePanel(top = 10, right = 10, id = 'controls', sliderInput('nb_fatalities', 'Minimum Fatalities', 1, 40, 10), dateRangeInput('date_range', 'Select Date', "2010-01-01", "2019-12-01"), ) , tags$style(type = "text/css", " html, body {width:100%;height:100%} #controls{background-color:white;padding:20px;} ") )

slide-28
SLIDE 28

BUILDING WEB APPLICATIONS WITH SHINY IN R

Add output: interactive map

server <- function(input, output, session){

  • utput$map <- leaflet::renderLeaflet({

leaflet() %>% addTiles() %>% setView( -98.58, 39.82, zoom = 5) }) }

slide-29
SLIDE 29

BUILDING WEB APPLICATIONS WITH SHINY IN R

slide-30
SLIDE 30

BUILDING WEB APPLICATIONS WITH SHINY IN R

Add reactive expression

rval_mass_shootings <- reactive({ mass_shootings %>% filter( date >= input$date_range[1], date <= input$date_range[2], fatalities >= input$nb_fatalities ) })

slide-31
SLIDE 31

BUILDING WEB APPLICATIONS WITH SHINY IN R

Update output: interactive map

  • utput$map <- leaflet::renderLeaflet({

rval_mass_shootings() %>% leaflet() %>% addTiles() %>% setView( -98.58, 39.82, zoom = 5) %>% addCircleMarkers( popup = ~ summary, radius = ~ fatalities, fillColor = 'red', color = 'red', weight = 1 ) })

slide-32
SLIDE 32

BUILDING WEB APPLICATIONS WITH SHINY IN R

slide-33
SLIDE 33

BUILDING WEB APPLICATIONS WITH SHINY IN R

Update app: add action button and modal

ui <- bootstrapPage( theme = shinythemes::shinytheme('simplex'), leaflet::leafletOutput('map', width = '100%', height = '100%'), absolutePanel(top = 10, right = 10, id = 'controls', sliderInput('nb_fatalities', 'Minimum Fatalities', 1, 40, 10), dateRangeInput('date_range', 'Select Date', "2010-01-01", "2019-12-01"), actionButton('show_about', 'About') ) ) server <- function(input, output, session){

  • bserveEvent(input$show_about, {

showModal(modalDialog(text_about, title = 'About')) }) }

slide-34
SLIDE 34

BUILDING WEB APPLICATIONS WITH SHINY IN R

slide-35
SLIDE 35

Let's practice!

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

slide-36
SLIDE 36

Wrap up video

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

Kaelen Medeiros & Ramnath Vaidya…

Instructors

slide-37
SLIDE 37

BUILDING WEB APPLICATIONS WITH SHINY IN R

Chapter 1

slide-38
SLIDE 38

BUILDING WEB APPLICATIONS WITH SHINY IN R

Chapter 2

slide-39
SLIDE 39

BUILDING WEB APPLICATIONS WITH SHINY IN R

Chapter 3

slide-40
SLIDE 40

BUILDING WEB APPLICATIONS WITH SHINY IN R

Chapter 4

slide-41
SLIDE 41

Congratulations!

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R