-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
44 lines (44 loc) · 1.08 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Load required packages
library(shinydashboard)
library(shiny)
library(bslib)
library(targets)
library(ggplot2)
library(plotly)
# Load pre-saved RDS file
national_data <- targets::tar_read(national_data)
head(national_data)
# Define UI components
color_by <- selectInput(
inputId = "color_var",
label = "Choose Color By:",
choices = c("employers", "strikes"),
selected = "strikes"
)
cards <- list(
card(
full_screen = TRUE,
card_header("Strikes"),
plotlyOutput("strikes") # Use plotlyOutput instead of plotOutput for interactive plots
)
)
ui <- page_sidebar(title = "Trade Union Data",
sidebar = color_by,
!!!cards)
server <- function(input, output) {
# Reactive expression to generate the ggplot
gg_plot <- reactive({
national_data |>
ggplot(aes(x = Year, y = strikes, size = employers, color = !!sym(input$color_var))) +
geom_point() +
theme_bw()
})
# Render the interactive plot using ggplotly
output$strikes <- renderPlotly({
ggplotly(gg_plot()) # Convert the ggplot object to an interactive plotly plot
})
}
# Run the application
shinyApp(ui, server)
# Run the application
shinyApp(ui, server)