Hi,
I have as output in R shiny a ggplot / geom bar.
I would like to highlight a bar when the user choose an input corresponding (meaning he choose a modality and the corresponding bar changes color)
I try to figure out for few days but I can't get.
This is UI :
checkboxGroupInput(inputId = "chauffage",
label = "Votre mode de chauffage :",
choices = list("électrique"=1, "gaz naturel individuel"=2, "gaz naturel collectif"=3,
"charbon"=4, "fioul domestique collectif"=5, "fioul domestique individuel"=6,
"GPL"=7, "réseau de chaleur"=8))),
box(id = "res2", title = "Estimer le chauffage :",
status = "success", solidHeader = FALSE, collapsible = FALSE,
width = NULL,
plotlyOutput("graph_chauffage"))
and server :
output$graph_chauffage <- renderPlotly ({
cols <- c("électrique"= "#e72f3f", "gaz naturel individuel"="#e72f3f", "gaz naturel collectif"= "#e72f3f", "charbon"="#e72f3f",
"fioul domestique individuel"="#e72f3f","GPL"= "#e72f3f", "réseau de chaleur"="#e72f3f", "fioul domestique collectif"="#e72f3f")
cols['input$chauffage'] <- "#9184be"
g <- ggplot(periode(), aes(x = type_chauffage, y = chauffage_en_kWh_par_logement, fill=type_chauffage)) +
geom_bar( stat = "identity") +
xlab("Type de chauffage" ) + ylab("Consommation énergétique en kWh/m²") +
scale_fill_manual(values=cols)+
theme(axis.text.x = element_text(angle = 45, hjust = 1),panel.background = element_rect(fill = "transparent"), legend.position = "none")+
geom_text(aes(label=chauffage_en_euro),vjust=1.6,size=3.5, color = "navy")
theme_minimal()
ggplotly(g) %>%
config(displaylogo = FALSE, collaborate = FALSE,
displayModeBar = FALSE)
})
Thanks for your help !