Open FedericoTrifoglio opened 3 years ago
I've changed the title as I believe it describes the error better or at least my understanding of it.
We temporarily "circumvented" the issue by removing the req()
from the renderPlotly
. Instead, we added the req() condition to a shinyjs::toggle
library(plotly)
shinyApp(
ui = fluidPage(
shinyjs::useShinyjs(), ## added
selectInput(inputId = "country",
label = "Select country",
choices = c("", "UK", "US", "China")),
div(id = "plotly", ## added
plotlyOutput("my_plot")
) ## added
),
server = function(input, output, session) {
output$my_plot <- renderPlotly({
# req(input$country) ## removed
data <- data.frame("Year" = 2016:2026,
"Value" = rnorm(11, 1000, 200))
data %>%
plot_ly(x = ~Year) %>%
add_lines(y = ~Value)
})
observe({
shinyjs::toggle(id = "plotly", condition = (input$country != ""))
})
}
)
To reproduce the error use this app
Then record a test. Take a snapshot without interacting with the dropdown box.
my_plot
shouldn't be rendered. After closing, you should get thisThe following two apps work fine.
Not entirely sure why the above works, but I suppose it's like output$my_plot doesn't even exist when the app is loaded up.
This is is just to prove that the issue is isolated to Plotly.