vegawidget / vegawidget

Htmlwidget renderer for Vega and Vega-Lite
https://vegawidget.github.io/vegawidget
Other
68 stars 13 forks source link

Error in vegawidget output when renderUI is present #217

Open zsigmas opened 1 year ago

zsigmas commented 1 year ago

Hi everyone,

I have found a weird interaction between vegawidget and renderUI in the application below.

It can be reproduced by:

  1. Checking the Send error Vega
  2. Checking the send error UI
  3. Unchecking the Send error Vega

When doing this the vega output remains an error when it should be fine.

I am really surprised as this two outputs do not share any inputs, so I am lost into finding the possible relation between both.

I have tried with other HTMLWidgets, leaflets and rbokeh, but I could not reproduce the issue.

library(magrittr)

vw <- list(
    `$schema` = vegawidget::vega_schema(), # specifies Vega-Lite    
    data = list(values = mtcars),
    mark = "point",
    encoding = list(
        x = list(field = "wt", type = "quantitative"),
        y = list(field = "mpg", type = "quantitative"),
        color = list(field = "cyl", type = "nominal")
    )
) %>%
    vegawidget::as_vegaspec() %>%
    vegawidget::vegawidget()

ui <- shiny::fluidPage(
    shiny::checkboxInput("error_vega", "Send Error Vega", value = FALSE),
    shiny::checkboxInput("error_ui", "Send Error UI", value = FALSE),
    vegawidget::vegawidgetOutput("spec_chart_vega"),
    shiny::uiOutput("ui")
)

server <- function(input, output, session) {
    output[["spec_chart_vega"]] <- vegawidget::renderVegawidget({
        if (input[["error_vega"]]) stop("hey")
        vw
    })

    output[["ui"]] <- shiny::renderUI({
        if (input[["error_ui"]]) stop("hey ui")
        "No Error"
    })
}

shiny::shinyApp(ui, server)

Thanks!

ijlyttle commented 10 months ago

Hi @zsigmas - I had some time over the holidays to look at this, and I have to say I'm stumped:

I'll keep looking at it though...