2025-09-18

OVERVIEW

UI.R CODE

For the ui.R, I present the sidebarLayout code that contains the inputs for the plot. The complete code ui.R code is in the Github repository.

sidebarLayout( # Sidebar (info and inputs)
  sidebarPanel(
    # Select countries
      selectInput(inputId="countries_sel", label = "Select countries:", 
                  choices = unique(countries), multiple = TRUE,
                  selected = c("Mexico", "United States of America")),
      # Select years 
      sliderTextInput(inputId = "years", label = "Years:", 
                      choices = 1950:2023, selected = c(1990, 2015),
                      grid = TRUE) ),
  # Main (plot)
  mainPanel(plotlyOutput("plot"))
  )

SERVER.R CODE

For the ui.R, I present the creation of the output plot (with plotly). The complete code server.R code is in the Github repository.

  # Plot with plotly 
  output$plot <- renderPlotly({
    plot_ly(data = data_filt_output(), x = ~year_i, y = ~temp, 
            color = ~name, type = 'scatter', mode = 'lines+markers') %>%
      layout(title = paste("Temperature by contry (",input$years[1],"-",
                      input$years[2],")", sep = ""),
        xaxis = list(title = "Year"),
        yaxis = list(title = "Temperature (°C)"))
    })