plotly / plotly/plotly.R

Snapshot function errors when the output itself is error

Open
#1,685 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at R/shiny.R around line 58, where snapshotPreprocessOutput parses the snapshot value. Reproduce the issue with the supplied shinytest example, including the renderPlotly output that returns an error, and verify that app$getAllValues() no longer fails when the snapshot output is not valid JSON.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization, testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.