-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple Plotly Outputs #124
Comments
I've also run into this. The example in the linked StackOverflow question reproduces currently on shinylive.
In the console I see errors like
@georgestagg Do you have any idea about the cause? Example applibrary(shiny)
library(bslib)
library(plotly)
data = data.frame(head(mtcars, 100))
choices = colnames(data)
choices = choices[-c(1)]
ui <- bslib::page_navbar(
bslib::nav_panel(
title = "Tab 1",
fillable = FALSE,
bslib::layout_sidebar(
sidebar = bslib::sidebar(
"Sidebar",
shiny::selectizeInput(
"select",
"Choose",
multiple = TRUE,
selected = character(0),
choices = choices
)
),
shiny::uiOutput("content")
)
)
)
server <- function(input, output) {
storage <- reactiveValues(color = list())
output$content <- shiny::renderUI({
req(input$select)
output_list <- lapply(input$select, function(parameter) {
layout_columns(
col_widths = c(8, 4),
bslib::card(
height = "400",
full_screen = TRUE,
bslib::card_header(
shiny::textOutput(paste0("title_", parameter))
),
bslib::layout_sidebar(
sidebar = bslib::sidebar(
shiny::selectInput(
paste0("select_color_", parameter),
"Marker color",
choices = choices,
selected = ifelse(parameter %in% names(storage$color), storage$color[[parameter]], choices[1])
)
),
plotlyOutput(paste0("plot_", parameter))
)
),
bslib::card(
card_header(
"Histogram"
),
plotlyOutput(paste0("histogram_", parameter))
)
)
})
do.call(tagList, output_list)
})
observe({
req(input$select)
lapply(input$select, function(parameter) {
output[[paste0("title_", parameter)]] <- shiny::renderText({
paste0("Plot ", parameter)
})
output[[paste0("plot_", parameter)]] <- renderPlotly({
plot_ly(
data,
x = ~mpg,
y = ~data[[parameter]],
color = ~data[[input[[paste0("select_color_", parameter)]]]],
type = 'scatter',
mode = 'markers'
)
})
output[[paste0("histogram_", parameter)]] <- renderPlotly({
plot_ly(
data,
x = ~data[[parameter]],
type = 'histogram'
)
})
})
})
observe({
req(input$select)
lapply(input$select, function(parameter) {
storage$color[[parameter]] <- input[[paste0("select_color_", parameter)]]
})
})
}
shinyApp(ui = ui, server = server) |
I think this is likely due to a change made to webR's Wasm version of the This is unfortunately a pretty strong requirement for widgets to work under Shinylive because synchronously loading XHR content through a JS Service Worker has a long-standing bug under Chromium (since 2016, possibly earlier). I know of a workaround, but it's a pretty nasty hack: explicitly adding |
Just linking to related (duplicate?) tickets: r-wasm/webr#330 posit-dev/shinylive#116 |
I had a similar issue with running multiple renderDataTable and adding |
Hello! Another issue I noticed with the reactivity is when working with prettySwitch toggling off does not show the correct reaction. Here is the same reproducible example from this thread with the added prettySwitch to toggle on and off the charts. You can turn the visibility of the charts on and once you turn it off the chart is still visible. The charts don't get updated with the sliderInput so it is technically turning "off" that reaction but is not reflected in the UI output. |
Hey Hazelvaq, I am really new to a lot of this but I have found that req does goofy things for me. Try changing the req to an if statement. # Bar plot 1 ---- Bar plot 2 ----output$barPlot2 <- plotly::renderPlotly({ |
Thank you! I need to try it out on my app now! |
Note that the issue with |
Hello,
A process that I can't seem to figure out is having multiple plotly plots appear at one time. I apologize if this has been addressed previously, but the only discussion I was able to find did not have a workaround solution. It can be found here
I am experiencing this exact issue. I have working examples of plotly plots being executed via a function or a module. Similar to the previous link, if I change a reactive input, all the plotly plots will appear and work correctly. It seems to be the initial load. Here is a reproducible example (Move the slider and the second plot will appear)
I did try setting a reactive input to be delayed via shinyjs, but in the shinyLive environment the delay did not work while the delay did work in my local shiny environment. Thank you for any suggestions/insights.
The text was updated successfully, but these errors were encountered: