Skip to content

Commit

Permalink
Merge pull request #24 from UBC-MDS/data_pro
Browse files Browse the repository at this point in the history
processed
  • Loading branch information
vincentho32 authored Feb 25, 2023
2 parents 15b9c42 + 0e1ed7b commit a2dab95
Show file tree
Hide file tree
Showing 3 changed files with 652,010 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
processed.R
rsconnect/

.Rhistory
47 changes: 37 additions & 10 deletions app.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
library(shiny)
library(ggplot2)
library(dplyr)
library(plotly)
library(leaflet)
library(leaflet.extras)
library(sf)
library(countrycode)
library(RColorBrewer)

# Load dataset
data <- read.csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-12-20/weather_forecasts.csv")
weather <- read.csv("data/processed/weather_pro.csv")

# Define UI
ui <- fluidPage(
Expand All @@ -22,11 +28,11 @@ ui <- fluidPage(

# Add dropdown menu input for selecting state
selectInput("state", "Select State:",
choices = unique(data$state)),
choices = unique(weather$state)),

# Add dropdown menu input for selecting city
selectInput("city", "Select City:",
choices = unique(data$city)),
choices = NULL),

# Add radio button input for selecting temperature or precipitation
radioButtons("data_type", "Select Data Type:",
Expand All @@ -42,20 +48,41 @@ ui <- fluidPage(
)

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

observe({
updateSelectInput(session, "city",
choices = unique(weather$city[weather$state == input$state]))
})

# Filter data based on user inputs
filtered_data <- reactive({
data %>%
filter(month >= input$month_range[1], month <= input$month_range[2]) %>%
filter(state == input$state, city == input$city)
weather %>%
filter(month >= input$month_range[1], month <= input$month_range[length(input$month_range)]) %>%
filter(state == input$state, city == input$city) %>%
group_by(month) %>%
summarise(observed_temp = mean(observed_temp, na.rm=TRUE),
observed_precip = mean(observed_precip, na.rm=TRUE))
})

# Create line plot based on filtered data and user data type input
output$line_plot <- renderPlot({
ggplot(filtered_data(), aes(x = month, y = ifelse(input$data_type == "Temperature", observed_temp, observed_precip))) +
geom_line() +
labs(x = "Month", y = input$data_type)
if (input$data_type == "Temperature"){
ggplot(filtered_data(), aes(x = month, y = observed_temp)) +
geom_point(color="violetred") +
geom_line(color="lightblue") +
scale_x_continuous(breaks = seq(1, 12, by = 1)) +
labs(x = "Month", y = "Temperature")
}
else{
ggplot(filtered_data(), aes(x = month, y = observed_precip)) +
geom_point(color="violetred") +
geom_line(color="lightblue") +
scale_x_continuous(breaks = seq(1, 12, by = 1)) +
labs(x = "Month", y = "Precipitation")
}
})

}

# Run app
Expand Down
Loading

0 comments on commit a2dab95

Please sign in to comment.