简体   繁体   English

从 linux 系统上的 R shiny downloadHandler 中删除目录结构

[英]Removing directory structure from R shiny downloadHandler on linux system

I'd like to know if it's possible to remove the tmp folder directory structure from the download file name of my shiny app, and if yes, how please.我想知道是否可以从我的 shiny 应用程序的下载文件名中删除 tmp 文件夹目录结构,如果可以,请问如何。 My shiny app uses tempfile() to generate a filename in the tempdir() with the initial part of the name given by an input (fieldName_f).我的 shiny 应用程序使用 tempfile() 在 tempdir() 中生成一个文件名,其中包含输入 (fieldName_f) 给出的名称的初始部分。 This works fine on my Windows computer, eg if input$fieldName_f <- 'Paddock1', the filename in the popup window displayed 'Paddock1Report420239b17634.html'.这在我的 Windows 计算机上运行良好,例如,如果输入 $fieldName_f <- 'Paddock1',弹出窗口 window 中的文件名显示为 'Paddock1Report420239b17634.html'。 However, when the codes run on the linux server where my app is hosted, the tmp directory will be appended before my input name, eg the output filename will be '_tmp_Rtmp53xNDh_Paddock1Report420239b17634.html', which is undesireable.但是,当代码在托管我的应用程序的 linux 服务器上运行时,tmp 目录将附加在我的输入名称之前,例如 output 文件名将是 '_tmp_Rtmp53xNDh_Paddock1Report420239b17634.html',这是不希望的。

I'm wondering if there is a way to set eg a junk path to ensure that the folder structure does not get saved in the filename in the downloadHandler please.我想知道是否有办法设置垃圾路径,以确保文件夹结构不会保存在 downloadHandler 的文件名中。

Thanks heaps!谢谢堆!

  frmd <- tempfile('report', tmpdir = tempdir(), fileext = '.Rmd') 
  output$downloadF <- downloadHandler(
    #specify a filename to save
    filename = function(){
      tempfile(paste0(input$fieldName_f, 'Report'), tmpdir = tempdir(), fileext = '.html')},    
    content = function(file){
      # Copy the template r markdown file to a temporary directory before processing it
      file.copy('reportF.Rmd', frmd, overwrite = T)
      rmarkdown::render(frmd, output_file = file)
    }
  )

I think that filename should simply be the filename that the user receives.我认为filename应该只是用户收到的文件名。 This should be a string.这应该是一个字符串。 Try尝试

filename = function(){
    paste0(input$fieldName_f, ' Report')}

Note that I also added a space before the word "Report", which is probably what you want.请注意,我还在“报告”一词之前添加了一个空格,这可能是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM