【问题标题】:Shiny Download an excel file闪亮 下载一个excel文件
【发布时间】:2016-09-12 11:43:37
【问题描述】:

我在 Linux 实例上设置了 shiny 服务器 我有一个名为 templates 的文件夹,其中有一个 excel 文件模板 用户进入网页并按下下载按钮,理论上他们应该能够在本地机器上的任何地方下载模板。

我已经看到Shiny download file not working帖子中的代码

当我尝试运行它时,我在我的 Windows 笔记本电脑上获得了一个保存到 my downloads 的文件,它被称为 NA 而不是名称 Template.xlsx

我的两个问题是

  • 是否可以提示用户本地保存文件的位置
  • 是否可以将其默认为XLSX

伪代码是

ui <- shinyUI(fluidPage(

 # Side Panel with Options
  fluidRow(
    column(4, wellPanel(
  id = "leftPanel",
  div(
    id = "Header",
    h3("Options"),
    tags$hr()
  ),
  div(
    h4("1.  Download the empty excel template"), 
    downloadButton("downloadBtn", "Download Excel Template")
      )
)))))

服务器

# Define server logic required
server <- shinyServer(
  function(input, output) {

output$downloadBtn <- downloadHandler(
  filename = function() {
    paste(input$filenames, sep='')
  },
  content = function(file) {
    myfile <- srcpath <- '/home/foo/Save to Database/templates/Template.xlsm'
    file.copy(myfile, file)
  }
  )})

【问题讨论】:

    标签: r excel shiny


    【解决方案1】:

    您正在使用paste(input$filenames, sep=''),但您没有在 UI 部分中定义 input$filenames。如果您将该行替换为"Template.xlsm"

    ,它应该可以工作

    【讨论】:

      猜你喜欢
      • 2016-05-02
      • 2017-11-03
      • 2017-07-26
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多