部署我的第一个闪亮的应用程序 - 简单的html解析器,让用户上传一个html文件,然后解析它以获取LinkedIn上的分享/提及/喜欢的信息 .
该应用程序在本地运行良好(在部署之前进行测试),Rstudio在部署时不会显示任何错误 . 但是,当我使用shinyapps链接运行它时,似乎上传无法完成,我没有得到任何输出 .
What it looks like locally
打开应用程序
正在上传.html文件
What it looks like on shinyapps.io
我已经编辑了文件名,因为它包含识别信息 .
代码如下:
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)
这可能与我有免费帐户的事实有关吗?正在上传的文件大小小于420kb .
我查看了以下问题,但他们没有解决上述问题:
Rstudio有一个类似的例子,使用 fileInput
可以在这里找到:https://shiny.rstudio.com/articles/upload.html
1 回答
它不是答案,但它仍然可能有帮助 . 我重写了你的代码,所以我可以执行它并在shinyappsio上传它 .
我把
actual_data
重写为:我使用了这个website的html .
运行应用程序 locally works fine 但上传到shinyapps.io后,这就是我在firefox中遇到的错误(500 - 内部服务器错误):
你在linux上试过这款应用吗? Shinyapps.io基于Linux,您可能必须在您的应用程序中包含其他软件包,甚至在Linux系统上安装软件,尽管我不确定这是否可能 .
当fileUpload上传一个csv文件而不是html时,一切都按预期工作,在本地和shinyapps.io上 . 所以问题似乎是html文件或html-scraping .