部署我的第一个闪亮应用程序——简单的 html 解析器,让用户上传 html 文件,然后解析它以获取 LinkedIn 上的分享/提及/喜欢的信息。
该应用程序在本地运行良好(在部署之前进行了测试),并且 Rstudio 没有显示任何部署错误。但是,当我使用闪亮应用程序链接运行它时,上传似乎无法完成,并且我没有得到任何输出。
本地看起来是什么样子
打开应用程序
上传 .html 文件
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。
我查看了以下问题,但它们没有解决上述问题:
- shinyapps.io 上的 Shiny 应用程序部署错误 https://stackoverflow.com/questions/37235038/shiny-app-deployment-error-on-shinyapps-io
- 部署闪亮应用程序时出错 https://stackoverflow.com/questions/33853411/error-in-deploying-a-shiny-app
- 无法在闪亮的服务器上部署闪亮的应用程序 https://stackoverflow.com/questions/24306571/unable-to-deploy-shiny-app-on-shiny-server?rq=1
Rstudio 有一个类似的例子,使用fileInput
可以在这里找到:https://shiny.rstudio.com/articles/upload.html https://shiny.rstudio.com/articles/upload.html