Skip to content
Snippets Groups Projects
Commit 2fd60290 authored by LE DURAND Matteo's avatar LE DURAND Matteo
Browse files

Merge branch '30-implementer-les-bonnes-pratiques-de-reactivite' into 'dev'

changement de reactiv() a reactiveValue() + observeEvent()

See merge request !25
parents 48821ad6 c910aaa2
No related branches found
Tags v6.0.0-RC4
2 merge requests!25changement de reactiv() a reactiveValue() + observeEvent(),!18MAJ de main de la branche dev
server <- function(input, output) {
filteredData <- reactive({
req(input$daterange)
all_data %>%
filter(updated_at >= as.Date(input$daterange[[1]]) & updated_at <= as.Date(input$daterange[[2]]))
})
observeEvent(input$daterange,{
updateSelectizeInput(inputId = "idprojet",label = "Projet : ",
choices = unique(filteredData()$project_name))
r <- reactiveValues(filteredData = NULL, filteredData2 = NULL)
# Daterange ----
observeEvent(input$daterange, {
req(input$daterange)
r$filteredData <- all_data %>%
filter(updated_at >= as.Date(input$daterange[[1]]) &
updated_at <= as.Date(input$daterange[[2]]))
updateSelectizeInput(
inputId = "idprojet",
label = "Projet : ",
choices = unique(r$filteredData$project_name)
)
})#----↑Observe Daterange
observeEvent(input$idprojet,{
output$lien <- renderUI({
# Générer une liste d'URLs basée sur input$idprojet
urls <- paste0("https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/", input$idprojet)
# Créer une liste de balises <a> pour chaque lien
urls <- paste0("https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/", input$idprojet) # Générer une liste d'URLs basée sur input$idprojet
links <- lapply(seq_along(input$idprojet), function(i) {
a(href = urls[i], target = "_blank", input$idprojet[i])
})
}
) # Créer une liste de balises <a> pour chaque lien
do.call(tagList, c(links, list(br()))) # Retourner les liens avec un saut de ligne après chacun
})
r$filteredData2 <- r$filteredData %>% dplyr::filter(project_name %in% input$idprojet )
#2eme graph
output$filteredPlot2 <- plotly::renderPlotly({
req(input$idprojet,cancelOutput = TRUE)
p <- ggplot2::ggplot(r$filteredData2, ggplot2::aes(x = updated_at, y = as.factor(project_name))) +
ggplot2::geom_jitter(ggplot2::aes(color = type, text = paste(updated_at, message, sep = "\n")),
size = 3, alpha = 0.5,
height = 0, width = 0.75
) +
ggplot2::labs(shape = "Type", color = "Type", x = "") +
ggplot2::scale_x_datetime(date_labels = "%d/%m", timezone = "Europe/Paris") +
gouvdown::theme_gouv() +
ggplot2::theme(
axis.text.x = ggplot2::element_text(angle = 0, hjust = 1),
axis.title.y = ggplot2::element_blank()
) +
gouvdown::scale_color_gouv_discrete(palette = "pal_gouv_qual2")
# Retourner les liens avec un saut de ligne après chacun
do.call(tagList, c(links, list(br())))
plotly::ggplotly(p, tooltip = "text")
})
})
filteredData2 <- reactive({
req(input$idprojet)
filteredData() %>% dplyr::filter(project_name %in% input$idprojet )
})
}) #----↑Observe idprojet----↑↑↑↑↑↑
output$filteredPlot <- plotly::renderPlotly({
p <- ggplot2::ggplot(filteredData(), ggplot2::aes(x = updated_at, y = as.factor(project_name))) +
req(input$daterange)
p <- ggplot2::ggplot(r$filteredData, ggplot2::aes(x = updated_at, y = as.factor(project_name))) +
ggplot2::geom_jitter(ggplot2::aes(color = type, text = paste(updated_at, message, sep = "\n")),
size = 3, alpha = 0.5,
height = 0, width = 0.75
......@@ -47,23 +70,6 @@
plotly::ggplotly(p, tooltip = "text")
})
#2eme graph
output$filteredPlot2 <- plotly::renderPlotly({
p <- ggplot2::ggplot(filteredData2(), ggplot2::aes(x = updated_at, y = as.factor(project_name))) +
ggplot2::geom_jitter(ggplot2::aes(color = type, text = paste(updated_at, message, sep = "\n")),
size = 3, alpha = 0.5,
height = 0, width = 0.75
) +
ggplot2::labs(shape = "Type", color = "Type", x = "") +
ggplot2::scale_x_datetime(date_labels = "%d/%m", timezone = "Europe/Paris") +
gouvdown::theme_gouv() +
ggplot2::theme(
axis.text.x = ggplot2::element_text(angle = 0, hjust = 1),
axis.title.y = ggplot2::element_blank()
) +
gouvdown::scale_color_gouv_discrete(palette = "pal_gouv_qual2")
plotly::ggplotly(p, tooltip = "text")
})
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment