generated from hannesdatta/template-team-project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.R
76 lines (66 loc) · 2.58 KB
/
app.R
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
library(shiny)
library(tidyverse)
library(fixest)
library(plotly)
# Load graph data
graph_data <- read_csv("data/graph_data.csv")
# Define UI
ui <- fluidPage(
titlePanel("Genre Preferences Analysis"),
mainPanel(
fluidRow(
column(6,
selectInput("genre_1", "Select Genre 1:", choices = unique(graph_data$genre)),
plotlyOutput("plot_output_1")
),
column(6,
selectInput("genre_2", "Select Genre 2:", choices = unique(graph_data$genre)),
plotlyOutput("plot_output_2")
)
),
br(),
p("Hover over a dot in the plot to see the exact value of the estimate, and click on the significance value on the index on the right to filter on significance.")
)
)
# Define server logic
server <- function(input, output, session) {
# Render the plots
output$plot_output_1 <- renderPlotly({
selected_genre_data <- reactive({
filtered_data <- graph_data %>%
filter(genre == input$genre_1)
return(filtered_data)
})
p <- ggplot(selected_genre_data(), aes(x = as.factor(sample), y = coef_value, color = factor(p_significance))) +
geom_point() +
geom_errorbar(aes(ymin = lower_ci, ymax = upper_ci), width = 0.2) +
scale_color_manual(values = c("red", "green"),
labels = c("Insignificant", "Significant")) +
xlab("Year") + ylab("Coefficient Value") + ggtitle(paste("Genre:", input$genre_1)) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(title = "Significance"))
# Convert ggplot to plotly
ggplotly(p, tooltip = c("x", "y"), click = "plot_click")
})
output$plot_output_2 <- renderPlotly({
selected_genre_data <- reactive({
filtered_data <- graph_data %>%
filter(genre == input$genre_2)
return(filtered_data)
})
p <- ggplot(selected_genre_data(), aes(x = as.factor(sample), y = coef_value, color = factor(p_significance))) +
geom_point() +
geom_errorbar(aes(ymin = lower_ci, ymax = upper_ci), width = 0.2) +
scale_color_manual(values = c("red", "green"),
labels = c("Insignificant", "Significant")) +
xlab("Year") + ylab("Coefficient Value") + ggtitle(paste("Genre:", input$genre_2)) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(title = "Significance"))
# Convert ggplot to plotly
ggplotly(p, tooltip = c("x", "y"), click = "plot_click")
})
}
# Run the application
shinyApp(ui = ui, server = server)