0

I really need an help for this as I'm totally lost and I tred all I could find around. I have a selectInput and I need to load a table for each of the possible choices. Unfortunately when I use the same file for two consecutive choices, the inputfile is not triggered and I cannot load the file for the second time. I cannot believe I'm the first who's tackling this... That's what I found around as possible solution but it seems not to work how can I update a shiny fileinput

Any hint will be more than welcome

library(shiny)
runApp(list(

  ui = bootstrapPage(
    tags$script('Shiny.addCustomMessageHandler("resetFileInputHandler", function(x) {   
           var el = $("#" + x);
           el.replaceWith(el = el.clone(true));
           var id = "#" + x + "_progress";     
           $(id).css("visibility", "hidden");
           });'
           ),

    sidebarPanel(
      fileInput("file1", NULL, width="80%"),

      selectInput('uploadFormat', label = "Select upload format", 
        choices = c(
            "Option 1" = 'f1',
            "Option 2" = 'f2',
            "Option 3" = 'f3'),
        selected = 'f1')

    ),

    mainPanel(
      verbatimTextOutput("summary"),
      uiOutput("Table")
    )
  ),

  server = function(input, output, session) {
    userEnv <- new.env()
    userEnv$tablecsv <- NULL

    observe({
      input$file1
      input$uploadFormat
      f <- input$uploadFormat
      if (!is.null(input$file1))
      if (is.null(userEnv$tablecsv[[f]]))
        (userEnv$tablecsv[[f]] <- read.table(input$file1$name, header = FALSE, sep=";", dec="."))
      session$sendCustomMessage(type = "resetFileInputHandler", "file1")
      T <- userEnv$tablecsv[[f]]
      output$Table <- renderTable({T})
    })

    output$summary <- renderText({
      return(paste("Uploaded file: ", input$file1$name))
    })
  }
))
Community
  • 1
  • 1
Stefano
  • 361
  • 1
  • 4
  • 21
  • You have lots of incomplete code here. Please describe what exactly you are trying to achieve. Maybe a sketch of what the interface will be like and what functions you need. – Xiongbing Jin Mar 22 '16 at 00:06
  • I would simply like to reset the file name of fileInput object otherwise, if I use the same one for two different selections, the object is not triggered. – Stefano Mar 23 '16 at 09:54

0 Answers0