Reputation: 2753
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:
Rstudio has a similar example using fileInput
that can be found here: https://shiny.rstudio.com/articles/upload.html
Upvotes: 11
Views: 3393
Reputation: 53
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 'curr' (a string value)</pre>
<h2>Traceback</h2>
<pre> stack traceback: /opt/openresty/luajit/share/lua/5.1/lapis/application.lua:73: in function 'add_params' /opt/openresty/luajit/share/lua/5.1/lapis/application.lua:394: in function 'handler' /opt/openresty/luajit/share/lua/5.1/lapis/application.lua:416: in function </opt/openresty/luajit/share/lua/5.1/lapis/application.lua:412> [C]: in function 'xpcall' /opt/openresty/luajit/share/lua/5.1/lapis/application.lua:412: in function 'dispatch' /opt/openresty/luajit/share/lua/5.1/lapis/nginx.lua:181: in function 'serve' access_by_lua(nginx.conf:232):1: in function <access_by_lua(nginx.conf:232):1></pre>
</div>
<div class="footer">lapis 1.0.4</div>
</body>
</html>
Upvotes: 1
Reputation: 9809
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.
Upvotes: 0