Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dataviz_gitlabr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DREAL Pays de la Loire
Centre de Services de la Donnée
dataviz_gitlabr
Merge requests
!25
changement de reactiv() a reactiveValue() + observeEvent()
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
changement de reactiv() a reactiveValue() + observeEvent()
30-implementer-les-bonnes-pratiques-de-reactivite
into
dev
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
LE DURAND Matteo
requested to merge
30-implementer-les-bonnes-pratiques-de-reactivite
into
dev
9 months ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
Closes
#30
0
0
Merge request reports
Viewing commit
c910aaa2
Show latest version
1 file
+
44
−
38
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
c910aaa2
changement de reactiv() a reactiveValue() + observeEvent()
· c910aaa2
LE DURAND Matteo
authored
9 months ago
server.R
+
44
−
38
Options
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"
)
})
}
Loading