Hi everyone,
I am a beginner in R and I am trying to create a simple Shinyapp and I have a problem of filtering my data to have a reactive plot depending on the filter. This is for a sport application (i.e. ice hockey)
I want to filter my data (2 differents metrics) depending on position or not. If I select anything in my sidebarpanel I want the mean of all my position if i select "position" i would like graphs of my two metrics split by position.
If anyone has a tip for that.
ui <- fluidPage(
titlePanel(
"CHARGE EXERCICE"
),
sidebarPanel(
width = 3,
selectizeInput(inputId = "Exercice",
label = "Drill",
choices = unique(df$Exercice),
selected = "",
multiple = TRUE),
),
mainPanel(
plotOutput(outputId = "TRIMP.min"),
plotOutput(outputId = "Mvt_intensity")
)
)
## server
server <- function(input, output, session){
dat <- reactive({
d <- df %>%
filter(Exercice == input$Exercice)
d
})
output$TRIMP.min <- renderPlot({
dat() %>%
ggplot(
aes(
x = Exercice,
y = TRIMP.min,
)) +
labs(y = "Intensite Cardio", x="") +
theme(axis.title.y = element_text(size = 14, face = "bold"))+
theme(axis.text.x = element_text(size = 14, face = "bold"))+
geom_bar(stat = "summary", fun = mean, fill = "red", )+
geom_hline(yintercept = mean(df$TRIMP.min), linetype = "dashed", size = 1, color="black")
})
output$Mvt_intensity <- renderPlot({
dat() %>%
ggplot(
aes(
x = Exercice,
y = Mvt_intensity,
)) +
labs(y = "Intensite Mouvement", x="") +
theme(axis.title.y = element_text(size = 14, face = "bold"))+
theme(axis.text.x = element_text(size = 14, face = "bold"))+
geom_bar(stat = "summary", fun = mean, fill = "black") +
geom_hline(yintercept = mean(df$Mvt_intensity), linetype = "dashed", size = 1, color="white")
})
}
shinyApp(ui, server)