Skip to content
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

Plot does not render if you call IMPosterior more than once #23

Closed
ignacio82 opened this issue Apr 23, 2019 · 2 comments
Closed

Plot does not render if you call IMPosterior more than once #23

ignacio82 opened this issue Apr 23, 2019 · 2 comments

Comments

@ignacio82
Copy link
Owner

@ignacio82 ignacio82 commented Apr 23, 2019

library(shiny)

  
  ui <- fluidPage(
    
    sidebarLayout(
      sidebarPanel(
        p('The modal graph will not populate when run 2+ times. The static plot is fine (needs to be uncommented)'),
        actionButton('run', 'Run')
      ),
      
      # Show a plot of the generated distribution
      mainPanel(
        IMPosterior::IMPosteriorOutput("staticplot")
      )
    )
  )
  
  server <- function(input, output, session) {
    
    im_object <- eventReactive(input$run,{
      IMPosterior::IMPosterior(sample(-500:500,50,replace = T), MME = 10, threshold = .7)
    })
    
    # output$staticplot <- IMPosterior::renderIMPosterior({
    #   im_object()
    # })
    
    output$modalplot <- IMPosterior::renderIMPosterior({
      im_object()
    })
    
    observeEvent(input$run,{
      req(im_object())
      showModal(modalDialog(
        IMPosterior::IMPosteriorOutput('modalplot'),
        title = 'Modal Plot',
        easyClose = T,
        size = 'm'
      ))
    })
    
  }
  
  # Run the application 
  shinyApp(ui = ui, server = server)

This is what the console shows:

IMPosterior.js:454 Uncaught ReferenceError: dims is not defined
    at Object.resize (IMPosterior.js:454)
    at Object.resize (htmlwidgets.js:825)
    at exports.OutputBinding.shinyBinding.resize (htmlwidgets.js:526)
    at output_binding_adapter.js:12
    at OutputBindingAdapter.onResize (utils.js:114)
    at HTMLDivElement.<anonymous> (init_shiny.js:309)
    at Function.each (jquery.min.js:2)
    at n.fn.init.each (jquery.min.js:2)
    at j (init_shiny.js:302)
    at Debouncer.$invoke (input_rate.js:56)

Apr 23 2019 9_02 AM - Edited

@timelyportfolio any chance that you can point me in the right direction on what could be causing this bug and how to fix it?

@stephanietuerk
Copy link
Collaborator

@stephanietuerk stephanietuerk commented Apr 25, 2019

  • It appears that when the plot is created a second time, htmlwidgets calls render(), resize(), and render(). This seems like strange behavior -- seems like it should either call resize() or render() but not both and certainly not render() twice.
  • When render() is called these two times, the width, height values passed in are 0, 0. When render() is called the first time, the value is as specified in R. (568, 500)

@ignacio82
Copy link
Owner Author

@ignacio82 ignacio82 commented Apr 25, 2019

Thanks @stephanietuerk . I'm wondering if this could be a bug in htmlwidgets. I will ask.

PS: Here is a video that shows the problem in case someone else is curious

Apr 25 2019 3_45 PM - Edited

ignacio82 pushed a commit that referenced this issue Apr 29, 2019
timelyportfolio added a commit to timelyportfolio/IMPosterior that referenced this issue May 2, 2019
This was referenced May 2, 2019
balajkhan07 pushed a commit to balajkhan07/vizdraws that referenced this issue Feb 4, 2022
balajkhan07 pushed a commit to balajkhan07/vizdraws that referenced this issue Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants