Skip to content

Commit

Permalink
feat: implementation dateRangeinput_dsfr + update
Browse files Browse the repository at this point in the history
tags: doc, test

pourquoi:
- avoir l'equivalent du dateRangeinput de shiny en version dsfr

quoi:
- implementation de dateRangeinput_dsfr et updatedateRangeinput_dsfr dans un flat specifique
- Modification daterange.js pour init value input
- completion table_correspondance

Issue #128
  • Loading branch information
MurielleDelmotte committed Jul 17, 2023
1 parent e4a891e commit 050be9d
Show file tree
Hide file tree
Showing 18 changed files with 480 additions and 71 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export(tabsetPanel_dsfr)
export(toggleSwitch_dsfr)
export(updateCheckboxGroupInput_dsfr)
export(updateCheckboxInput_dsfr)
export(updateDateRangeInput_dsfr)
export(updateNumericInput_dsfr)
export(updateRadioButtons_dsfr)
export(updateRadioGroupButtons_dsfr)
Expand Down
21 changes: 11 additions & 10 deletions R/daterangeinput_dsfr.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#' dateRangeInput_dsfr
#'
#' @param inputId inputId
#' @param label label
#' @param start character La date de début au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour.
#' @param end character La date de fin au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour.
#' @param label label
#' @param separator character Chaîne à afficher entre les zones de saisie de début et de fin de dates.
#'
#' @importFrom assertthat assert_that
#' @importFrom purrr map
Expand All @@ -31,12 +32,12 @@
#' fluidRow_dsfr(
#' # sans vecteur nommé
#' dateRangeInput_dsfr(inputId = "daterange1",
#' label = "Date range:", start = "2001-01-01")
#' label = "Date range:", start = "2001-01-01",separator = "à")
#' )
#' )
#' server <- function(input, output, session) {
#'
#' observeEvent(input$daterange1, ignoreNULL = FALSE , {
#' observeEvent(input$daterange1, {
#' print(input$daterange1)
#' })
#'
Expand All @@ -49,10 +50,12 @@ dateRangeInput_dsfr <- function(
inputId,
label,
start = NULL,
end = NULL
end = NULL,
separator = "to"
) {
# check les params
assertthat::assert_that(is.character(inputId))
assertthat::assert_that(is.character(separator))
assertthat::assert_that(is.character(label))


Expand All @@ -72,12 +75,10 @@ dateRangeInput_dsfr <- function(
inputId = inputId,
label = label,
start = start,
end = end
) %>%
parse_html()

end = end,
separator = separator
) #%>%
#parse_html()

# session$sendCustomMessage("dateRangeInput_dsfr_js",
# message = list(id = inputId))

}
7 changes: 5 additions & 2 deletions R/daterangeinput_dsfr_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#' @param start character La date de début au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour.
#' @param end character La date de fin au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour.
#' @param label label
#' @param separator character Chaîne à afficher entre les zones de saisie de début et de fin de dates.
#'
#' @importFrom htmltools htmlTemplate
#' @importFrom purrr pmap
Expand All @@ -15,7 +16,8 @@ dateRangeInput_dsfr_template <- function(
inputId,
label,
start,
end
end,
separator
) {


Expand All @@ -29,7 +31,8 @@ dateRangeInput_dsfr_template <- function(
inputId = inputId,
label = label,
start = start,
end = end
end = end,
separator = separator
)

}
97 changes: 91 additions & 6 deletions R/mod_input_limited_choices.R
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,59 @@ mod_input_limited_choices_ui <- function(id){
)
)

)
),
tabPanel_dsfr(
id = ns("tab7"),
title = "dateRangeInput_dsfr()",
content = tagList(
fluidRow_dsfr(
column_dsfr(
12,
h3("Demo dateRangeInput_dsfr()"),
# Adding space to the column
# https://www.systeme-de-design.gouv.fr/elements-d-interface/fondamentaux-techniques/espacement
extra_class = "fr-my-6w"
),
column_dsfr(
3,
dateRangeInput_dsfr(inputId = ns("dateRangeInput"),
label = "Date range:",
start = "2001-01-01",
end = "2023-07-07",
separator = "\u00e0"),
verbatimTextOutput(
outputId = ns("dateRangeInputvalue")
)
)
),
fluidRow_dsfr(
column_dsfr(
4,
extra_class = "fr-my-6w",
actionButton_dsfr(
inputId = ns("updatedateRangeInput"),
label = "Mettre \u00e0 jour le label"
)
),
column_dsfr(
4,
extra_class = "fr-my-6w",
actionButton_dsfr(
inputId = ns("updatedateRangeInput2"),
label = "Mettre \u00e0 jour le start"
)
),
column_dsfr(
4,
extra_class = "fr-my-6w",
actionButton_dsfr(
inputId = ns("updatedateRangeInput3"),
label = "Mettre \u00e0 jour le end"
)
)
)

)
)
)
Expand All @@ -370,7 +423,7 @@ mod_input_limited_choices_server <- function(id){
choices = LETTERS[1:10]
)

## checkboxinput
## checkboxinput ----
output$outputcheckbox <- renderText({
paste("Valeur du checkbox :", input$mycheckboxInput)
})
Expand All @@ -391,7 +444,7 @@ mod_input_limited_choices_server <- function(id){
)
})

## checkboxgroupinput
## checkboxgroupinput ----
output$outputcheckboxgroup <- renderText({
paste("Valeur du checkboxgroup :", paste0(input$mycheckboxgroupInput, collapse = " "))
})
Expand All @@ -414,7 +467,7 @@ mod_input_limited_choices_server <- function(id){
)
})

## radioButtons
## radioButtons ----
output$outputespece <- renderText({
paste("Esp\u00e8ce :", input$espece)
})
Expand All @@ -437,7 +490,7 @@ mod_input_limited_choices_server <- function(id){
)
})

## radioGroupButtons
## radioGroupButtons ----
output$outputespece_radiogroupbutton <- renderText({
paste("Esp\u00e8ce radiogroupbutton :", input$espece_radiogroupbutton)
})
Expand Down Expand Up @@ -475,7 +528,7 @@ mod_input_limited_choices_server <- function(id){
})


## toggle switch
## toggle switch ----
output$toggleswitchvalue <- renderText({
paste0("La valeur du toggleSwitch est ", input$toggleswitch)
})
Expand All @@ -495,7 +548,7 @@ mod_input_limited_choices_server <- function(id){
)
})

## selectinput
## selectinput ----
observeEvent(input$updateselectinput, {
updateSelectInput_dsfr(
inputId = "selectinput",
Expand All @@ -518,6 +571,38 @@ mod_input_limited_choices_server <- function(id){
)
})

## dateRangeInput ----

output$dateRangeInputvalue <- renderText({
paste0("La valeur du dateRangeInput est ", paste0(input$dateRangeInput, collapse = "/"))
})

observeEvent(input$updatedateRangeInput, {
updateDateRangeInput_dsfr(
session = session,
inputId = "dateRangeInput",
label = paste(sample(letters, 10), collapse = "")
)

})

observeEvent(input$updatedateRangeInput2, {
new_start = sample(seq(as.Date('2000/01/01'), Sys.Date(), by="day"), 1)
updateDateRangeInput_dsfr(
session = session,
inputId = "dateRangeInput",
start = new_start
)
})

observeEvent(input$updatedateRangeInput3, {
new_end = sample(seq(as.Date('2000/01/01'), Sys.Date(), by="day"), 1)
updateDateRangeInput_dsfr(
session = session,
inputId = "dateRangeInput",
end = new_end
)
})

})
}
Expand Down
15 changes: 12 additions & 3 deletions R/shinygouv-dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ add_dsfr_deps <- function(tag, version = get_dsfr_version()) {
),
script = list(
list(type = "text/javascript", src = "shiny-compat.js"),
list(type = "text/javascript", src = "navbarPage.js"),
list(type = "text/javascript", src = "daterange.js"),
list(type = "text/javascript", src = "daterange2.js")
list(type = "text/javascript", src = "navbarPage.js")
),
all_files = TRUE
),
Expand All @@ -53,6 +51,17 @@ add_dsfr_deps <- function(tag, version = get_dsfr_version()) {
package = "shinygouv",
all_files = TRUE
),
daterangeinput_deps = htmlDependency(
name = "daterangeinput",
version = version,
src = c(file = "external_deps"),
script = list(
list(type = "text/javascript", src = "daterange.js"),
list(type = "text/javascript", src = "daterangeinputShinyCustomMessage.js")
),
package = "shinygouv",
all_files = TRUE
),
radiogroupbutton_deps = htmlDependency(
name = "radiogroupbuttons",
version = version,
Expand Down
90 changes: 90 additions & 0 deletions R/updatedaterangeinput_dsfr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# WARNING - Generated by {fusen} from /dev/flat_composants/flat_dateRangeInput.Rmd: do not edit by hand

#' updateDateRangeInput_dsfr
#'
#' @param inputId inputId
#' @param label label
#' @param start character La date de début au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour.
#' @param end character La date de fin au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour.
#' @param session la session, la valeur par défaut est getDefaultReactiveDomain().
#' @importFrom shiny updateCheckboxInput
#' @return html
#'
#' @export
#' @examples
#' ## Only run examples in interactive R sessions
#' if (interactive()) {
#'
#' library(shiny)
#'
#' ui <- fluidPage_dsfr(
#' dateRangeInput_dsfr(inputId = "daterange1",
#' label = "Date range:", start = "2001-01-01",separator = "à"),
#' actionButton_dsfr("go", "Change label"),
#' actionButton_dsfr("go2", "Change start"),
#' actionButton_dsfr("go3", "Change end")
#' )
#'
#' server <- function(input, output, session) {
#' observeEvent(input$daterange1, {
#' print(input$daterange1)
#' })
#'
#'
#' observeEvent(input$go, {
#' updateDateRangeInput_dsfr(
#' session = session,
#' inputId = "daterange1",
#' label = "new label"
#' )
#'
#' })
#'
#'
#' observeEvent(input$go2, {
#' updateDateRangeInput_dsfr(
#' session = session,
#' inputId = "daterange1",
#' start = "2000-01-01"
#' )
#'
#' })
#'
#' observeEvent(input$go3, {
#' updateDateRangeInput_dsfr(
#' session = session,
#' inputId = "daterange1",
#' end = "2020-01-01"
#' )
#'
#' })
#' }
#' shinyApp(ui, server)
#' }
updateDateRangeInput_dsfr <- function(inputId,
label = NULL,
start = NULL,
end = NULL,
session = shiny::getDefaultReactiveDomain()) {


ns <- session$ns

if (!is.null(label)) {
session$sendCustomMessage("updateDateRangeInputLabel",
list(inputId = ns(inputId),
label = label))
}

if (!is.null(start)) {
session$sendCustomMessage("updateDateRangeInputStart",
list(inputId = ns(inputId),
start = start))
}

if (!is.null(end)) {
session$sendCustomMessage("updateDateRangeInputEnd",
list(inputId = ns(inputId),
end = end))
}
}
Loading

0 comments on commit 050be9d

Please sign in to comment.