Snapshot function errors when the output itself is error
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
Plotly uses snapshotPreprocessOutput to remove any output values that are randomly generated. This is great.
However, if the render function outputs an error, the result is not a valid JSON. Because of this, the snapshotPreprocessOutput function errors out and frameworks like shinytest error out as well.
Example code:
library(plotly)
ui <- fluidPage(
checkboxInput("go", label="Render plot"),
plotlyOutput("plot")
)
server <- function(input, output, session) {
output$plot_plotly <- renderPlotly({
shiny::req(input$go) #induce a silent.error if input$go is FALSE
ggplot(data.frame(x=rnorm(1000))) +
geom_histogram(aes(x=x))
})
}
shinyApp(ui=ui, server=server)
Test code:
library(shinytest)
app <- ShinyDriver$new(path="tmp/")
app$getAllValues()
app$getAllValues() reports an error, because fetching the snapshot URL reports an error 500.
The issue can be easily solved in
https://github.com/ropensci/plotly/blob/bcae42bbeea8d8368fb3ca881243e6acd0c661b4/R/shiny.R#L58
I suggest you check if value is a character string before parsing as JSON.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 R/shiny.R 大约第 58 行开始,这里 snapshotPreprocessOutput 会解析 snapshot 值。使用提供的 shinytest 示例重现该问题,包括返回错误的 renderPlotly 输出,并验证当 snapshot 输出不是有效 JSON 时,app$getAllValues() 不再失败。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization, testing
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100