JohnCoene / echarts4r

🐳 ECharts 5 for R
http://echarts4r.john-coene.com/
Other
595 stars 81 forks source link

echarts in modal windows depending on input change does not flush properly #482

Closed Patrikios closed 1 year ago

Patrikios commented 1 year ago

Reprex under:

> version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          4                           
minor          2.2                         
year           2022                        
month          10                          
day            31                          
svn rev        83211                       
language       R                           
version.string R version 4.2.2 (2022-10-31)
nickname       Innocent and Trusting   

> packageVersion("echarts4r")
[1] ‘0.4.4’

> packageVersion("shiny")
[1] ‘1.7.3’
app <- shinyApp(
  ui = fluidPage(
    selectInput(
      "species",
      "Select spiecies",
      sort(unique(iris$Species)),
      "virginica"
    )
  ),
  server = function(input, output) {
    observeEvent(input$species, {
      showModal(modalDialog(
        echarts4rOutput("plot"),
        easyClose = TRUE,
        footer = NULL
      ))
    })

    output$plot <- renderEcharts4r({
      subset(iris, Species == input$species) |>
        e_charts(Sepal.Length) |>
        e_line(Sepal.Width) |>
        e_tooltip(trigger = "axis")
    })
  }
)

runApp(app)

The default select input "virginica" dependent output renders Okay (as it is the first render outcome cached???) however the other 2 Species render only after, for a brief moment, the outcome of "virginica" is displyed, only then the correct output is to be seen.

Obviously, this happens only in modal dialogues, when you bind output directly into fluidPage, it works as expected.

How can I flush before rendering? Something like JS function:

flushEchart = function() {
                          Shiny.setInputValue('unknown_proper_echart_input_value', 'null');
                        }

?

Patrikios commented 1 year ago

solved by suggestion as can be seen @ https://github.com/rstudio/shiny/issues/3731#issuecomment-1331249998