8

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

Start

Uploading an .html file

enter image description here

What it looks like on shinyapps.io

enter image description here

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

Isak
  • 355
  • 3
  • 11
Gautam
  • 2,055
  • 1
  • 16
  • 39
  • An error in browser console? – Tarun Lalwani May 22 '18 at 16:42
  • @TarunLalwani tried three different browsers on two different OS - same result. – Gautam May 22 '18 at 17:13
  • Could you include the code for `parsingFunction` ? Or at least a small example of it? Otherwise your code is not reproducible on its own. – SeGa May 22 '18 at 20:05
  • I also see no call to `input$infile$datapath`, which stores the path to the uploaded file, unless your doing that in the parse function. – SeGa May 22 '18 at 20:12
  • 1
    @SeGa included some basic code which calls `input$infile$datapath` to return a really simple `data.frame` object. Actual function tries to locate users, find similarities to previous events and brings up additional information referenced from a local database. – Gautam May 22 '18 at 21:31

2 Answers2

0

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.

SeGa
  • 8,183
  • 3
  • 22
  • 54
  • Thanks for the answer! I don't have access to a Linux system but I did try from a Unix system (MacOS) with the same outcome. However, that shouldn't be the problem since Shinyapps creates a local clone on their server (or so I understand). The only package I'm using is `rvest` which is available on CRAN i.e. standardized and confirmed to work with R distributions for different OS-es. I had more packages previously (`ggmaps`, `geosphere`, `ggplot`, `plotly` etc.) but I've reduced my problem to the simplest case with a single CSS selector and still no results. – Gautam May 22 '18 at 21:24
  • I'll try on a ShinyServer on Linux tomorrow. We'll see what it says then, but for now I suspect the error is on the shinyapps.io-side. Some packages in R do require further installations on linux (rgdal for example). Are you using the free version of shinyapss.io or anything above that, as it would give you access to premium support, otherwise you might also check their google [group](https://groups.google.com/forum/#!forum/shinyapps-users) – SeGa May 22 '18 at 21:32
  • I have a free account. Checked the google group - someone had the same issue but I couldn't find a solution that works for me. They have moved to Rstudio community from google-groups. I posted my question there too but no response: https://community.rstudio.com/t/error-uploading-html-file-to-shiny-app/7249 – Gautam May 22 '18 at 21:34
  • On a Shiny Server on Linux, your app works fine, afer installing rvest without any problems. So again, I suspect the error is on the shinyapps.io side. – SeGa May 23 '18 at 07:39
  • Didn't get a chance to look at this sooner. If that is indeed the case, there isn't much I can do then :( – Gautam May 23 '18 at 20:27
0

Another close-to-non-answer for posterity's sake. For context, I've also run into this issue a few times before on shinyapps.io, but never on Mac or Windows when running from RStudio. In particular, I have gotten this with zipped files (in some cases zipped .txt files, in other cases ESRI Shapefiles). The formatted HTML I see in the upload progress bar is shown below.

As a frequent VPN and proxy user, I find that connection drops during the upload process can cause this for me. If there's a chance your internet connection is troublesome, I would look into that.


  <!DOCTYPE HTML>
<html lang="en">
   <head>
      <title>Error</title>
      <style type="text/css"> body { color: #222; background: #ddd; font-family: sans-serif; margin: 20px; } h1, h2, pre { margin: 20px; } .box { background: white; overflow: hidden; box-shadow: 1px 1px 8px gray; border-radius: 1px; } .footer { text-align: center; font-family: serif; margin: 10px; font-size: 12px; color: #A7A7A7; } </style>
   </head>
   <body>
      <div class="box">
         <h1>Error</h1>
         <pre>/opt/openresty/luajit/share/lua/5.1/lapis/application.lua:73: attempt to index local &#039;curr&#039; (a string value)</pre>
         <h2>Traceback</h2>
         <pre> stack traceback: /opt/openresty/luajit/share/lua/5.1/lapis/application.lua:73: in function &#039;add_params&#039; /opt/openresty/luajit/share/lua/5.1/lapis/application.lua:394: in function &#039;handler&#039; /opt/openresty/luajit/share/lua/5.1/lapis/application.lua:416: in function &lt;/opt/openresty/luajit/share/lua/5.1/lapis/application.lua:412&gt; [C]: in function &#039;xpcall&#039; /opt/openresty/luajit/share/lua/5.1/lapis/application.lua:412: in function &#039;dispatch&#039; /opt/openresty/luajit/share/lua/5.1/lapis/nginx.lua:181: in function &#039;serve&#039; access_by_lua(nginx.conf:232):1: in function &lt;access_by_lua(nginx.conf:232):1&gt;</pre>
      </div>
      <div class="footer">lapis 1.0.4</div>
   </body>
</html>
waiguoren
  • 13
  • 2