【问题标题】:Shiny file Input accepting all file types闪亮的文件输入接受所有文件类型
【发布时间】:2020-10-11 22:29:57
【问题描述】:

我在 Shiny 上创建了一个表单,它具有 fileInput 按钮,仅上传 .pdf 扩展名文件。但在测试时我发现它接受所有类型的文件类型,但是我在 fileInput 的接受参数中提到了 .pdf,如下所示代码:

 fileInput("fileid","Upload .pdf file only",multiple = FALSE, accept = c('.pdf'),width = "250px")

下面的屏幕截图,接受所有类型的文件:

接受 .xls 文件类型

接受 .csv 文件类型:

我正在寻找一种解决方案,限制用户仅上传 .pdf 文件,如果选择了其他文件,则不允许用户上传。

任何帮助将不胜感激。 :)

【问题讨论】:

    标签: r web-applications shiny shinyapps


    【解决方案1】:

    您可以而且必须在您的服务器功能中验证自己。 fileInput 为您提供 MIME 类型,您可以在加载之前验证它的类型是否正确。

    output$DisplayFileContent <- renderPrint({
      req(input$fileid)
      # Check for file type
      if (input$fileid$type != "application/pdf") stop("No PDF")
      
      pdffile <- readBin(con=input$file_input$datapath, what = 'raw',n=input$file_input$size)
      # ... more code to show file content
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 2017-07-17
      • 1970-01-01
      相关资源
      最近更新 更多