我正在尝试制作从该 api 获取数据的闪亮应用程序:https ://www.riigiteenused.ee/api/et/all 。我需要使用 jsonlite::fromJSON,因为它有很好的 flatten 功能。当我使用以下代码时(最小的例子,在现实生活中我用数据做更多的事情):
library(jsonlite)
data=fromJSON("https://www.riigiteenused.ee/api/et/all")
server <- function(input, output) {
output$tekst <- renderText({
nchar(data)
})
}
ui <- fluidPage(
sidebarLayout(
sidebarPanel(),
mainPanel(textOutput("tekst"))
))
shinyApp(ui = ui, server = server)
我收到以下错误消息:
Error in open.connection(con, "rb") :
Peer certificate cannot be authenticated with given CA certificates
我尝试了以下方法(绕过 ssl verify peer):
library(RCurl)
raw <- getURL("https://www.riigiteenused.ee/api/et/all",
.opts = list(ssl.verifypeer = FALSE), crlf = TRUE)
data=fromJSON(raw)
它读取原始数据,但弄乱了 JSON(validate(raw) 显示词法错误:字符串中的无效字符 \n,这会导致以下错误):
Error: lexical error: invalid character inside string.
ressile: laevaregister@vta.ee. Avaldusele soovitatavalt lis
(right here) ------^
我尝试过的一个想法是:
data=fromJSON(readLines("https://www.riigiteenused.ee/api/et/all"))
它在我的计算机上运行良好,但是当我将其上传到 shinyapps.io 应用程序不起作用并且从日志中我看到错误:
Error in file(con, "r") : https:// URLs are not supported
有人可以给我一个线索,如果有办法使用 jsonlite fromJSON 函数从 https toshiny 应用程序加载 JSON 数据?
我的会话信息如下:
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=Estonian_Estonia.1257 LC_CTYPE=Estonian_Estonia.1257
[3] LC_MONETARY=Estonian_Estonia.1257 LC_NUMERIC=C
[5] LC_TIME=Estonian_Estonia.1257
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] jsonlite_0.9.19 httr_1.0.0 RCurl_1.95-4.7 bitops_1.0-6 shiny_0.12.2
loaded via a namespace (and not attached):
[1] Rcpp_0.12.2 digest_0.6.8 mime_0.4 R6_2.1.1
[5] xtable_1.7-4 magrittr_1.5 stringi_1.0-1 curl_0.9.4
[9] tools_3.2.2 stringr_1.0.0 httpuv_1.3.3 rsconnect_0.4.1.4
[13] htmltools_0.2.6