Error deploying shiny app that uses fileInput to upload data

随声附和 提交于 2021-01-27 04:20:59

问题


Deploying my first shiny app -- simple html parser that lets users upload an html file and then parses it to get info on shares/mentions/likes on LinkedIn.

The app runs fine locally (tested before deployment) and Rstudio does not show any errors with deployment. However, when I run it using the shinyapps link it appears the upload fails to complete and I don't get any output.

What it looks like locally

Opening App

Uploading an .html file

What it looks like on shinyapps.io

I've redacted the file name since it contains identifying information.

The code is as below:

library(rvest)
library(shiny)
ui <- fluidPage(
  # theme = "https://bootswatch.com/4/superhero/bootstrap.css",
  title = "LinkedIn Report",

  fluidRow(
    column(12,
           fileInput("infile", "Choose .html file", 
              accept = "text/html", multiple = F) )
  ),

  fluidRow(
    column(12,
           tableOutput("savedLocation") )
  ), 

  fluidRow(
    column(12,
           tableOutput("parsedData") ),
    column(8, 
           downloadButton("downloadData", "Download"))
  )

)


server <- function(input, output){
  dd <- reactive(input$infile)

  output$savedLocation <- renderTable({
    if(is.null(input$infile)){
      return(data.frame(Elapsed = character(), 
                        Time = character(),
                        Name = character(), 
                        Action = character()))
    }else{
      return(dd())
    }
  })

  actual_data <- reactive({
    if(is.null(input$infile)){
      asdad <- data.frame(Elapsed = character(), 
                          Time = character(),
                          Name = character(), 
                          Action = character())
    }else{
      notifications <- read_html(input$infile$datapath)
      name_action <- gsub("\\n", "", notifications %>% html_nodes(".nt-card__text--3-line") %>% html_text())
      tme <- trimws(gsub("\\n", "", notifications %>% html_nodes(".nt-card__time-ago") %>% html_text()))
      action <- notifications %>% html_nodes(".nt-card__text--3-line strong") %>% html_text
      nme <- trimws( sapply(1:length(name_action), function(z) gsub(action[z], "", name_action[z])))


  asdad <- data.frame(Elapsed = tme, Time = elap(tme), Name = nme, Action = action)
    }
    return(asdad)
  })

  output$parsedData <- renderTable({ actual_data()})

  output$downloadData <- downloadHandler(
    filename = "yourdata.csv", 
    content = function(filename){ write.table(actual_data(), file = filename, 
                                              row.names = F, sep = ",")}
  )
}

shinyApp(ui = ui, server = server)

Could this have something to do with the fact that I have a free account? The file that is being uploaded is less than 420kb in size.

I've looked at the following questions but they don't address the above:

  1. Shiny app deployment error on shinyapps.io
  2. Error in deploying a shiny app
  3. Unable to deploy shiny app on shiny server

Rstudio has a similar example using fileInput that can be found here: https://shiny.rstudio.com/articles/upload.html


回答1:


Its not an answer, but it still might be helpfull. I rewrote your code, so I can execute it and also upload it on shinyappsio.

I rewrote the actual_data reactive to:

 actual_data <- reactive({
    if(is.null(input$infile)){
      asdad <- data.frame(Elapsed = character(), 
                          Time = character(),
                          Name = character(), 
                          Action = character())
    }else{
      asdad1 <- read_html(input$infile$datapath)
      asdad2 <- html_nodes(x = asdad1, css = "#titleCast span.itemprop")
      asdad <- html_text(asdad2)
  }
    return(asdad)
  })

And I used the html from this website.

Running the app locally works fine but after uploading to shinyapps.io, thats the error I am getting in firefox (500 - Internal Server Error):

Error /usr/share/luajit/share/lua/5.1/lapis/application.lua:73: attempt to index local 'curr' (a string value)

Traceback

stack traceback:
/usr/share/luajit/share/lua/5.1/lapis/application.lua:73: in function 'add_params'
/usr/share/luajit/share/lua/5.1/lapis/application.lua:394: in function 'handler' /usr/share/luajit/share/lua/5.1/lapis/application.lua:416: in function [C]: in function 'xpcall'
/usr/share/luajit/share/lua/5.1/lapis/application.lua:412: in function 'dispatch' /usr/share/luajit/share/lua/5.1/lapis/nginx.lua:181: in function 'serve' access_by_lua(redx.conf:162):1: in function

Did you try the app on linux? Shinyapps.io is based on linux, and you might have to include other packages in your app or even install software on the linux-system, although I'm not sure if thats even possible.

When the fileUpload uploads a csv-file instead of html, everything works as expected, locally and on shinyapps.io. So the problem seems to be with html-files or with the html-scraping.



来源:https://stackoverflow.com/questions/49825288/error-deploying-shiny-app-that-uses-fileinput-to-upload-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!