闪亮的服务器端在调用网络调用时没有响应

server side in shiny not responding while calling web call

我正在开发一个闪亮的应用程序,当 UI 中提供了 url 时,我需要从 Web 获取和下载文件。

在服务器站点上,当我尝试获取文件并将其下载到特定位置时,应用程序出错。我猜这是因为反应过程。

下面提供了示例代码,请告诉我我哪里错了。

服务器端: {

library(shiny)
require(XML)
require(utils)

shinyServer(function(input, output, session) {

dfile <- "~/dest/temp.pdf"
dest <- "~/dest"
url<-input$pdfurl

download.file(url,dfile)

myfiles <- list.files(path = dest, pattern = "pdf",  full.names = TRUE)

lapply(myfiles, function(i)    system(paste('"D:/pranav/software/xpdf/bin64/pdftotext.exe"', paste0('"', i, '"')), wait = FALSE) )

}

客户端:

{

library(shiny)

row <- function(...) {
  tags$div(class="row", ...)
}

col <- function(width, ...) {
  tags$div(class=paste0("span", width), ...)
}

shinyUI(fluidPage(
        fluidRow(
          column(12,style = "background-color:#ADD8C9;",
                 titlePanel("Document Reader"),
        fluidRow(
          column(8,style = "background-color:#ADD8C6;", 
                 tags$div(
                   class = "container",

                   row(
                     col(3, textInput("pdfurl", "PDF URL"))
                   ),
                   row(
                     col(6, style = "width:600px;",htmlOutput('pdfviewer'))
                   )
                 )
          ),

          column(4,style = "background-color:#ADD8C9;", 

          )

        )


      )
      )
)
)

}

Shiny 通过反应性发挥作用。您可以在 http://shiny.rstudio.com/articles/reactivity-overview.html

上阅读更多相关信息

没有 ui-side 无法重现您的问题,但您可以尝试这样的操作:

shinyServer(function(input, output, session) {
    observeEvent(input$pdfurl, {
        download.file(input$pdfurl,dfile)
        myfiles <- list.files(path = dest, pattern = "pdf",  full.names = TRUE)
        lapply(myfiles, function(i)    system(paste('"D:/pranav/software/xpdf/bin64/pdftotext.exe"', paste0('"', i, '"')), wait = FALSE) )
    })
}