server <- function(input, output) {
# Reactive function to fetch data
fred_indicator <- reactive({
data <- fredr(series_id = input$indicator,
observation_start = start_date,
observation_end = end_date)
print(paste("Data fetched for indicator:", input$indicator)) # Debug statement
print(head(data)) # Print first few rows of the fetched data
data
})
# Reactive function to filter data
fred_data <- reactive({
data <- fred_indicator() |>
filter(between(date, input$range[1], input$range[2]))
print(paste("Data filtered for range:", input$range[1], "to", input$range[2])) # Debug statement
data
})
# Plotting function
output$lineChart <- renderPlot({
data <- fred_data()
print("Plotting data") # Debug statement before plotting
ggplot(data, aes(x = date, y = value)) +
geom_line(color = "navyblue") +
labs(x = "", y = names(vars[which(vars == input$indicator)])) +
theme_minimal()
})
}