【问题标题】:Clear fileInput control on switching of tabs inside a tabsetPanel in Shiny R在 Shiny R 中的 tabsetPanel 内切换选项卡时清除 fileInput 控件
【发布时间】:2016-03-30 07:15:00
【问题描述】:

每当用户在 tabsetPanel 内的两个选项卡之间切换时,我都需要重置 fileInput 控件。

我已经查看了有关此主题的现有问题,但无法根据我的需要对其进行调整。 how can I update a shiny fileInput object?

我没有清除按钮或刷新按钮 - 选项卡上的开关应该这样做。

下面是我的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"))))
        )
      )
    )
  )
)

用户可以在名为“FixedwidthTab”的第一个选项卡中上传文件,然后切换到名为“DelimitedTab”的第二个选项卡 - 反之亦然。两个选项卡都有 fileInput 控件,我需要它们在选项卡切换时重置。

【问题讨论】:

    标签: tabs shiny


    【解决方案1】:

    这对你有用吗?我将fileInputs 与一些服务器端渲染的UI 进行了交换,只要选择了相应的选项卡,它就会重新渲染fileInputs

    见下面的代码:

    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'))
          }
        })
    
      }
    )
    

    如果您对所提供的答案有任何疑问,请询问!

    【讨论】:

      猜你喜欢
      • 2017-07-21
      • 2018-06-21
      • 1970-01-01
      • 2014-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-24
      相关资源
      最近更新 更多