Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

130 composant implementation de fileinput #133

Merged
merged 9 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

!.github/*/*
docs
.Rproj.user
Expand All @@ -9,3 +8,4 @@ docs
inst/doc
rsconnect
deliverables
zz_rsconnect*
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Authors@R: c(
comment = c(ORCID = "0000-0002-4816-4624")),
person("Yohann", "Mansiaux", , "yohann@thinkr.fr", role = "aut",
comment = c(ORCID = "0000-0002-8905-6603")),
person("Jean-Daniel", "LOMENEDE", role = "aut"),
person("David", "Granjon", role = "ctb"),
person("Alan", "Dipert", role = "ctb")
)
Expand All @@ -31,6 +32,7 @@ Imports:
purrr (>= 0.3.4),
shiny (>= 1.7.1),
stringr (>= 1.4.0),
tools,
utils,
XML (>= 3.99.0.10)
Suggests:
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(checkboxGroupInput_dsfr)
export(checkboxInput_dsfr)
export(column_dsfr)
export(convert_to_dsfr)
export(fileInput_dsfr)
export(dateRangeInput_dsfr)
export(fluidPage_dsfr)
export(fluidRow_dsfr)
Expand All @@ -25,6 +26,7 @@ export(selectInput_dsfr)
export(showModal_dsfr)
export(sliderInput_dsfr)
export(tabPanel_dsfr)
export(tableOutput_dsfr)
export(tabsetPanel_dsfr)
export(toggleSwitch_dsfr)
export(updateCheckboxGroupInput_dsfr)
Expand Down
12 changes: 6 additions & 6 deletions R/actionbutton_dsfr.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# WARNING - Generated by {fusen} from dev/flat_composants/flat_actionButton.Rmd: do not edit by hand
# WARNING - Generated by {fusen} from /dev/flat_composants/flat_actionButton.Rmd: do not edit by hand

#' actionButton_dsfr
#'
Expand All @@ -14,7 +14,7 @@
#' if (interactive()) {
#' library(shiny)
#' library(shinygouv)
#'
#'
#' ui <- fluidPage_dsfr(
#' header = header_dsfr(
#' intitule = "Intitule",
Expand All @@ -38,13 +38,13 @@
#' paste("Vous avez cliqu\u00e9", input$test, "fois sur le bouton")
#' })
#' }
#'
#'
#' shinyApp(ui, server)
#' }
actionButton_dsfr <- function(
inputId,
label,
class = NULL
inputId,
label,
class = "fr-p-1w"
) {
actionButton_dsfr_template(
inputId,
Expand Down
63 changes: 63 additions & 0 deletions R/fileinput_dsfr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# WARNING - Generated by {fusen} from /dev/flat_composants/flat_fileInput.Rmd: do not edit by hand

#' fileInput_dsfr
#'
#'
#' @param inputId id de l'input
#' @param label etiquette du bouton d'import, par exemple "choisir fichier"
#' @param message eventuelles indications complementaires, par exemple "fichier images de moins de 2 Mo"
#'
#' @return html
#' @importFrom assertthat assert_that
#' @export
#'
#' @examples
#'
#' if (interactive()) {
#' ui <- fluidPage_dsfr(
#' fluidRow_dsfr(
#' column_dsfr(width = 4,
#' fileInput_dsfr(inputId = "file1", label = "Importez vos données", message = "seul le format csv est pris en charge"),
#' br(),
#' checkboxInput_dsfr(inputId = "header", label = "Utiliser les en-tetes du fichier")
#' ),
#' column_dsfr(width = 8,
#' tableOutput_dsfr("contenu")("contenu")
#' )
#' )
#' )
#'
#' server <- function(input, output) {
#' output$contenu <- renderTable({
#' file <- input$file1
#' ext <- tools::file_ext(file$datapath)
#'
#' req(file)
#' validate(need(ext == "csv", "Veuillez choisir un fichier csv svp"))
#'
#' read.csv2(file$datapath, header = input$header, nrows = 12)
#' })
#' }
#'
#' shinyApp(ui, server)
#' }
#'
#'
fileInput_dsfr <- function(
inputId,
label,
message
) {

assertthat::assert_that(is.character(inputId))
assertthat::assert_that(is.character(label))
assertthat::assert_that(is.character(message))

fileInput_dsfr_template(
inputId = inputId,
label = label,
message = message
) %>%
parse_html()

}
28 changes: 28 additions & 0 deletions R/fileinput_dsfr_template.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# WARNING - Generated by {fusen} from /dev/flat_composants/flat_fileInput.Rmd: do not edit by hand

#' template pour fileInput_dsfr
#'
#' @param inputId id de l'input
#' @param label etiquette du bouton d'import, par exemple "choisir fichier"
#' @param message eventuelles indications complementaires, par exemple "seuls les fichiers csv sont acceptes"
#' @importFrom htmltools htmlTemplate
#' @return html
#' @noRd
fileInput_dsfr_template <- function(
inputId,
label,
message
) {

htmltools::htmlTemplate(
filename = system.file(
get_dsfr_version(with_v = TRUE),
"composant",
"fileInput.html",
package = "shinygouv"
),
inputId = inputId,
label = label,
message = message
)
}
37 changes: 36 additions & 1 deletion R/mod_input_actions.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,33 @@ mod_input_actions_ui <- function(id){
label = "Afficher le spinner pendant 5 secondes"
)
)
)
),

tags$br(),
tags$hr(),

fluidRow_dsfr(
column_dsfr(
12,
h3("Demo fileInput_dsfr()"),
# Adding space to the column
# https://www.systeme-de-design.gouv.fr/elements-d-interface/fondamentaux-techniques/espacement
extra_class = "fr-my-2w"
),
column_dsfr(width = 4,
fileInput_dsfr(inputId = ns("user_file"), label = "Importez vos donn\u00e9es", message = "Seul le format csv est pris en charge."),
br(),
checkboxInput_dsfr(inputId = ns("header_csv"), label = "Utiliser les en-tetes du fichier", value = TRUE),
extra_class = "fr-px-1w"),
column_dsfr(width = 8,
tableOutput_dsfr(outputId = ns("contenu")),
extra_class = "fr-px-1w"
)
),

tags$br(),
tags$hr()


)
}
Expand Down Expand Up @@ -130,7 +156,16 @@ mod_input_actions_server <- function(id){
}
)

output$contenu <- renderTable({
req(input$user_file)
user_file <- input$user_file
ext <- tools::file_ext(user_file$datapath)
validate(need(ext == "csv", "Veuillez choisir un fichier csv svp"))
read.csv2(user_file$datapath, header = input$header_csv, nrows = 5)
})

})

}

## To be copied in the UI
Expand Down
30 changes: 30 additions & 0 deletions R/tableoutput_dsfr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# WARNING - Generated by {fusen} from /dev/flat_composants/flat_tableOutput.Rmd: do not edit by hand

#' tableOutput_dsfr
#'
#' @param outputId nom d'output a partir duquel lire la table
#' @return html
#'
#' @export
#'
#' @examples
#'
#' if (interactive()) {
#' # table example
#' shinyApp(
#' ui = fluidPage_dsfr(
#' fluidRow_dsfr(
#' column_dsfr(12,
#' tableOutput_dsfr('table')
#' )
#' )
#' ),
#' server = function(input, output) {
#' output$table <- renderTable(iris)
#' }
#' )
#' }
tableOutput_dsfr <- function (outputId) {
assertthat::assert_that(is.character(outputId))
shiny::div(id = outputId, class = "fr-table shiny-html-output")
}
2 changes: 1 addition & 1 deletion dev/flat_composants/flat_actionButton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ test_that("actionButton_dsfr_template works", {
actionButton_dsfr <- function(
inputId,
label,
class = NULL
class = "fr-p-1w"
jengelaere marked this conversation as resolved.
Show resolved Hide resolved
) {
actionButton_dsfr_template(
inputId,
Expand Down
Loading
Loading