简体   繁体   English

R Shiny 应用程序在 Linux 服务器上运行时下载文件

[英]Downloading Files when R Shiny App is running on a Linux Server

I am working on a Shiny app which creates a URL based on user inputs and runs that URL using the browseURL() function. I am working on a Shiny app which creates a URL based on user inputs and runs that URL using the browseURL() function. The URL downloads a csv file. URL 下载 csv 文件。 The app needs to reside on a Linux server and when I try to run it from the server, it keeps giving me an error.该应用程序需要驻留在 Linux 服务器上,当我尝试从服务器运行它时,它一直给我一个错误。 When I run it on my machine, it opens Google Chrome (which is my default web browser) and downloads the csv file in the default "downloads" folder (which is what I expected it to do).当我在我的机器上运行它时,它会打开 Google Chrome(这是我的默认 web 浏览器)并在默认的“下载”文件夹中下载 csv 文件(这是我期望它做的)。 Below is a simplified version of what I am trying to do.下面是我正在尝试做的简化版本。 Could someone please help me figure out why it works on my machine but not on the Linux server?有人可以帮我弄清楚为什么它可以在我的机器上运行,但不能在 Linux 服务器上运行吗? I just started this project and I don't know about Linux servers.我刚开始这个项目,我不知道 Linux 服务器。 The errors look like -错误看起来像 -

/usr/bin/xdg-open: 778: /usr/bin/xdg-open: www-browser: not found
/usr/bin/xdg-open: 778: /usr/bin/xdg-open: links2: not found
/usr/bin/xdg-open: 778: /usr/bin/xdg-open: elinks: not found

Any help is greatly appreciated.任何帮助是极大的赞赏。

library(shiny)
library(shinyWidgets)


ui <- fluidPage(
   
   # Application title
   titlePanel("Testing File Download on Linux Server"),
   
   
   sidebarLayout(
      sidebarPanel(
         textInput("SID","Specify SIDs", value = ""),
         actionBttn("goButton","Go!",color = "default",style = "unite",size = "lg")
      ),
      
      mainPanel()
      
           
   )
)


server <- function(input, output,session) {
 ts_info<-eventReactive(input$goButton,{
   TS_url<-paste("http://xyzserver&request=getList&station_no=",input$SID,"&format=csv&downloadfilename=testingdownload",sep="")

   return(TS_url)   
   

 })
 observe({
   browseURL(ts_info())
 }) 
   
}

# Run the application 
shinyApp(ui = ui, server = server)

By using browseURL you are asking to open a web browser on the server which obviously is not able to do because it's not the place to do this.通过使用browseURL,您要求在服务器上打开web 浏览器,这显然无法执行,因为它不是执行此操作的地方。 The browser must be launched on your computer, not the server.浏览器必须在您的计算机上启动,而不是在服务器上启动。

You can format and provide the url as an uiOutput您可以格式化并提供 url 作为 uiOutput

sidebarPanel(
         textInput("SID","Specify SIDs", value = ""),
         actionBttn("goButton","Go!",color = "default",style = "unite",size = "lg"),
         uiOutput("dlLink")
      ),
output$dlLink <- renderUI(tags$a(href=tsInfo(),"Download"))

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

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