dreamRs / datamods

Shiny modules to import and manipulate data into an application or addin

Home Page:https://dreamrs.github.io/datamods/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set list of files format allowed

erifa1 opened this issue · comments

Hi

Is it possible to have an argument file_extensions in the import_modal() function to control list of possible file formats allowed?

Thanks!
Etienne

Thanks for the suggestion.
import_modal() has now a file_extensions argument, re-install from CRAN to have last version.

Victor

Hello

Just a feedback, file_extensions keep default value when from argument is set only on "file" value.

Thanks again

See:

library(shiny)
library(datamods)

ui <- fluidPage(
  # Try with different Bootstrap version
  # theme = bslib::bs_theme(version = 4),
  fluidRow(
    column(
      width = 4,
      checkboxGroupInput(
        inputId = "from",
        label = "From",
        choices = c("env", "file", "copypaste", "googlesheets", "url"),
        selected = c("file", "copypaste")
      ),
      actionButton("launch_modal", "Launch modal window")
    ),
    column(
      width = 8,
      tags$b("Imported data:"),
      verbatimTextOutput(outputId = "name"),
      verbatimTextOutput(outputId = "data")
    )
  )
)

server <- function(input, output, session) {

  observeEvent(input$launch_modal, {
    req(input$from)
    import_modal(
      id = "myid",
      from = input$from,
      file_extensions = c(".tsv", ".rdata", ".xls"),
      title = "Import data to be used in application"
    )
  })

  imported <- import_server("myid", return_class = "tbl_df")

  output$name <- renderPrint({
    req(imported$name())
    imported$name()
  })

  output$data <- renderPrint({
    req(imported$data())
    imported$data()
  })
}

if (interactive())
  shinyApp(ui, server)

Thanks that's fixed.