Plotly does not show error message when inputs are invalid for Quarto dashboards in R

Open
#13,759 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
frontend, web-dev

Research direction

Start with the minimal .qmd reproduction in the issue and compare its Quarto dashboard behavior with the regular .R case described. Trace the interaction between plotly::renderPlotly() and shiny::validate(); done means the specified validation message appears for an out-of-range input instead of the previous plot.

Written by the indexing model from the issue text.

Description

bug dashboards plotly shiny
I have:
  • searched the issue tracker for similar issues
  • installed the latest version of Quarto CLI
  • formatted my issue following the Bug Reports guide
Bug description

Hi Quarto team, I believe I encountered a bug when plotly is used with shiny::validate() for Quarto dashboards in R.

I could not get plotly::renderPlotly() to work well with shiny::validate() when invalid values are inputted. Instead of showing the error message specified by validate() when there's an invalid input, renderPlotly() will display the previous plot. As far as I know, this bug only occurs for Quarto dashboards (.qmd) and does not appear in regular R scripts (.R). I have included an MRE below.

I appreciate any insight or tips. Thank you so much.

Steps to reproduce
---
title: "Testing renderPlotly with shiny::validate()"
format: dashboard
server: shiny
---
```{r}
#| label: setup
library(shiny)
library(plotly)
library(ggplot2)
```

```{r}
sliderInput("min_mpg", "Minimum MPG:", min = 10, max = 30, value = 15)
plotlyOutput("myPlot")
```

```{r}
#| context: server
output$myPlot <- renderPlotly({
  # Validate that the input value is within an acceptable range
  validate(
    need(input$min_mpg >= 10 && input$min_mpg <= 25, 
         "Please select a minimum MPG between 10 and 25.")
  )
  
  # Filter data based on the validated input
  filtered_mtcars <- mtcars[mtcars$mpg >= input$min_mpg, ]
  
  # Create a ggplot object
  p <- ggplot(filtered_mtcars, aes(x = wt, y = mpg)) +
    geom_point() +
    labs(title = paste("Cars with MPG >= ", input$min_mpg))
  
  # Convert ggplot to plotly
  ggplotly(p)
})

```
Actual behavior

When the user input, input$min_mpg, exceeds the range of valid inputs set by validate() (10 to 25 in this example), renderPlotly() will display the previous, outdated plot like so:

Image
Expected behavior

What I expected was for renderPlotly() to respect all the parameters set by validate(), which means that it should've displayed the specified error message when it detected that input$min_mpg was an invalid input over 25 like so:

Image
Your environment

-IDE: RStudio 2024.09.1+394
-OS: MacOS Sequoia 15.6.1

Quarto check output
Quarto 1.8.26
[✓] Checking environment information...
      Quarto cache location: /Users/ac3656/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.6.3: OK
      Dart Sass version 1.87.0: OK
      Deno version 2.3.1: OK
      Typst version 0.13.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.8.26
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Tex:  (not detected)

[✓] Checking Chrome Headless....................OK
      Using: Chrome found on system
      Path: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
      Source: MacOS known location

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.9.6
      Path: /Library/Developer/CommandLineTools/usr/bin/python3
      Jupyter: 5.7.2
      Kernels: python3

(|) Checking Jupyter engine render....Traceback (most recent call last):
  File "/Applications/quarto/share/jupyter/jupyter.py", line 20, in <module>
    from notebook import notebook_execute, RestartKernel
  File "/Applications/quarto/share/jupyter/notebook.py", line 15, in <module>
    from yaml import safe_load as parse_string
ModuleNotFoundError: No module named 'yaml'
There is a requirements.txt file in this directory. Is this for a venv that you need to restore?

WARN: Error encountered when rendering files
[✓] Checking Jupyter engine render....OK


Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

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.

More from quarto-dev/quarto-cli

All issues in quarto-dev/quarto-cli

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.