Explore a dataset with Shiny

Case Studies: Building Web Applications with Shiny in R

Dean Attali

Shiny Consultant

Explore a dataset with Shiny

Dataset

+ Interactive environment

+ View data

+ Filter data

+ Download data

= Shiny app

Case Studies: Building Web Applications with Shiny in R

Visualize data as a table

country continent year lifeExp pop gdpPercap
Afghanistan Asia 1952 28.801 8425333 779.445315
Afghanistan Asia 1957 30.332 9240934 820.85303
Afghanistan Asia 1962 31.997 10267083 853.10071
Afghanistan Asia 1967 34.02 11537966 836.197138
Afghanistan Asia 1972 36.088 13079460 739.981106
Afghanistan Asia 1977 38.438 14880372 786.11336
Afghanistan Asia 1982 39.854 12881816 978.011439
Afghanistan Asia 1987 40.822 13867957 852.39595
Afghanistan Asia 1992 41.674 16317921 649.34140
Afghanistan Asia 1997 41.763 22227415 635.34135
Case Studies: Building Web Applications with Shiny in R

Tables in shiny

  • Tables are output

    • Outputs use output placeholder functions in UI:
    tableOutput("my_table")
    
    • Outputs use render functions in the server:
    output$my_table <- renderTable({
        gapminder
    })
    
Case Studies: Building Web Applications with Shiny in R

Filtering table data

  • Inputs can be used to filter

    • Add input to UI:
    selectInput("country", "Country",
                choices = levels(gapminder$country))
    
    • Filter data using input:
  output$my_table <- renderTable({
      subset(gapminder, country == input$country)
  })
Case Studies: Building Web Applications with Shiny in R

Select input choices

  • choices argument of selectInput() can be any list of strings

    • choices can be subset of variable
    selectInput("country", "Country",
                choices = levels(gapminder$country)[1:10])
    
    • choices can be expanded to add new values
    selectInput("country", "Country",
                choices = c("any", levels(gapminder$country)))
    
Case Studies: Building Web Applications with Shiny in R

Let's practice!

Case Studies: Building Web Applications with Shiny in R

Preparing Video For Download...