Reproducible Pitch: Shiny App

Coursera Data Science Specialization Assignment

Felipe Ruiz Bruzzone

2024-03-22

Overview

This is an R Markdown presentation built as part of the Developing Data Products of the Coursera & John Hopkins University Data Science Specialization program. In the next slides you will find:

Visualizing economics data

Our app enables an easy visualization of economic database (ggplot2 package).

Its responsive aspect is defined by the user selection of the variable to visualize.

Behind the scenes, it loads the economic database and builds a geom_line object that show the evolution of the selected variable through time.

User interface code

# Define UI for application that draws a geom_line
fluidPage(
    # Application title
    titlePanel("USA economics database: visualization"),
    # Sidebar with a select input for specific variables of economics database
    sidebarLayout(
        sidebarPanel(
            selectInput(inputId = "variable", label = "Variable to visualize:",
                        choices = c("Population" = "pop", "Unemployed" = "unemploy",
                                    "Price Consumer Index" = "pce")),
            helpText("Please pick a variable to visualize")
        ),
        # Show a plot of the selected variable
        mainPanel(
          h1("Presentation"),
          p("This shiny app helps to visualize three variables of the economics R database."),
          br(),
          p("Using the right side panel, you can select one of three available variables to visualize."),
            plotOutput("tsplot")
        )
    )
)

Server code

# Define server logic required to draw a histogram
function(input, output) {
    output$tsplot <- renderPlot({
    # draw the histogram with the specified variables
        ggplot() +
        geom_line(data = economics,
                  aes_string(x = "date", y = input$variable))
    })
}