-
Notifications
You must be signed in to change notification settings - Fork 391
Description
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:
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:
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