假设我的水管工的东西.r文件如下所示.通过使用chrome访问路径并查看除\plotly端点之外的预期输出,我可以成功地测试每个端点.
在我的浏览器中访问时(即.,http://localhost:8000/plotly)我得到"发生异常错误".我不是在使用R Studio,我是在使用
pr("plumber.R") %>% pr_run(port=8000)
关于我的错误在哪里有什么建议吗?
###水管工.R
library(plotly)
#* Plot a histogram
#* @serializer png
#* @get /plot
function() {
rand <- rnorm(100)
hist(rand)
}
#* Return the sum of two numbers
#* @param a The first number to add
#* @param b The second number to add
#* @get /sum
function(a, b) {
as.numeric(a) + as.numeric(b)
}
#* Echo back the input
#* @get /dat
function() {
data.frame(id = c(1,2,3,4), v2 = c(5,6,7,8))
}
#* @apiTitle HTML widgets API#* @apiTitle HTML widgets API
#* Return interactive plot using plotly
#* @serializer htmlwidget
#* @get /plotly
function() {
fig <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)
fig
}
编辑以显示如何使用Pandoc解决此问题
我是用Vanilla RGui 4.1.3实现的,而不是RStudio IDE.所以,我手动安装了Pandoc 2.17.1.1.按照下面@jpiversen的建议,我做了以下事情.
我首先手动将setwd()用于本地安装Pandoc的位置.我需要这个,因为htmlwidgets:::find_pandoc()
没有路径参数,它扫描目录.设置工作目录后,运行
htmlwidgets:::find_pandoc()
htmlwidgets:::.pandoc$version
htmlwidgets:::.pandoc$dir
这解决了问题,现在我可以查看plotly端点.