0

I need to reset the fileInput control whenever the user switches between two tabs inside a tabsetPanel.

I have looked up the existing questions on this topic but haven't been able to tailor it to my needs. how can I update a shiny fileInput object?

I dont have a clear button or a refresh button - the switch on tabs should do this.

Below is my ui.R

fluidPage(
  fluidRow(column(width=10, 
    tabsetPanel(id="tabPanelOptions",
      tabPanel(value="FixedwidthTab", "Fixed width", 
        br(),
        fluidRow(column(width=12, fileInput('layoutfile', 'Upload Excel file to define layout', accept = '.xlsx')))
      ),
      tabPanel(value="DelimitedTab", "Delimited",
        br(),
        fluidRow(column(width=5, textInput("separator", "Field separator:",","))), 
        fluidRow(
          column(width=5, checkboxInput("quotes","Quoted texts?",FALSE)),   
          column(width=5, checkboxInput("header","Files contains header (column names)",FALSE))
        ),
        fluidRow(column(width=10, textInput("expcolumns", "Expected variables in file","27"))),
        fluidRow(column(width=10, fileInput('headerfile', '(Optional) Upload CSV file to define attribute names', accept = c('text/csv','text/comma-separated-values', 'text/tab-separated-values', 'text/plain','.csv','.txt')))),
        br(),
        fluidRow(
          column(width=5,conditionalPanel(condition= "input.header == false",uiOutput("choose_columns"))),
          column(width=5,conditionalPanel(condition= "input.header == false", uiOutput("rename_columns"))))
        )
      )
    )
  )
)

User can upload files while in the first tab called "FixedwidthTab" and then switch to the second tab called "DelimitedTab" - and vice versa. Both tabs have fileInput controls and I need them to reset on tab switching.

Community
  • 1
  • 1
Sandeep
  • 473
  • 1
  • 7
  • 27

1 Answers1

0

would this be working for you? I exchanged the fileInputs with some server side rendered UI, which re-renders fileInputs whenever the corresponding tab is being selected.

See code below:

shinyApp(
  ui = shinyUI(
    fluidPage(
      fluidRow(column(width=10, 
        tabsetPanel(id="tabPanelOptions",
          tabPanel(value="FixedwidthTab", "Fixed width", 
            br(),
            fluidRow(column(width=12, uiOutput("file1")))
          ),
          tabPanel(value="DelimitedTab", "Delimited",
            br(),
            fluidRow(column(width=5, textInput("separator", "Field separator:",","))), 
            fluidRow(
              column(width=5, checkboxInput("quotes","Quoted texts?",FALSE)),   
              column(width=5, checkboxInput("header","Files contains header (column names)",FALSE))
            ),
            fluidRow(column(width=10, textInput("expcolumns", "Expected variables in file","27"))),
            fluidRow(column(width=10, uiOutput("file2"))),
            br(),
            fluidRow(
              column(width=5,conditionalPanel(condition= "input.header == false",uiOutput("choose_columns"))),
              column(width=5,conditionalPanel(condition= "input.header == false", uiOutput("rename_columns")))
            )
          )
        )
      ))
    )
  ),

  server = function(input, output){

    output$file1 <- renderUI({
      if(input$tabPanelOptions == "FixedwidthTab"){
        fileInput('layoutfile', 'Upload Excel file to define layout', accept = '.xlsx')
      }
    })

    output$file2 <- renderUI({
      if(input$tabPanelOptions == "DelimitedTab"){
        fileInput('headerfile', '(Optional) Upload CSV file to define attribute names',
         accept = c('text/csv','text/comma-separated-values','text/tab-separated-values',
         'text/plain','.csv','.txt'))
      }
    })

  }
)

Please ask, if you have questions about the provided answer!

K. Rohde
  • 9,439
  • 1
  • 31
  • 51