【发布时间】:2020-02-08 07:09:36
【问题描述】:
我对使用 R 和 Shiny 比较陌生。目前,我在尝试从 Dropbox 访问 html 文件时遇到错误:冲突(HTTP 409),这很好,我知道原因。我确实有一个问题是试图找到一种方法来更改错误代码消息。
我尝试了几种形式的验证和尝试捕获。
library(shiny)
library(rdrop2)
library(httr)
ui <- # Define UI for dataset viewer application
shinyUI(pageWithSidebar(
headerPanel("Test DropBox html Docs to Shiny"),
sidebarPanel(
selectInput("Cat", "Choose a Category:",
choices = c("A", "B", "C")),
selectInput("Year", "Choose a Year:",
choices = c("2012", "2011")),
downloadButton("downFile", "Download File"),
width = 2),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Html Pages", htmlOutput("viewReport"))),
width = 10)
)
)
#IMPORTANT: The two lines below needs to be run just one time unless the token is deleted
# Create Token
token <- drop_auth()
# Save token
saveRDS(token, "droptoken.rds")
token <- readRDS("droptoken.rds")
server <- shinyServer(function(input, output) {
# ---------------------------------------------------
filePutReport <- reactive(
paste(input$Cat, "_", input$Year, "_Doc.html", sep = "")
)
filePutReport2 <- reactive({
# Search if the file exists in DropBox
drop_download(path = paste("shiny_docs/shinydbtest/", filePutReport(), sep = ""),
overwrite = TRUE, local_path = "./www",
dtoken = token)
filePutReport()
})
# Show Html Pages
output$viewReport <- renderUI({
tags$iframe(seamless = "seamless", width = "1400", height = "1000",
src = filePutReport2()
)
})
###
output$downFile <- downloadHandler(
# generate bins based on input$bins from ui.R
filename = function() {
paste0(filePutReport() )
},
content = function(file){
file.copy(from = paste0("./www/", filePutReport2() ), to = file, overwrite = TRUE)
}
)
})
shinyApp(ui = ui, server = server)
而不是简单的“错误:冲突(HTTP 409)”,我希望客户端可能能够理解的消息。欢迎任何和所有建议。提前感谢您的帮助。
【问题讨论】: