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

onRender called after onResize does not have new sizes for viz #59

Closed
nstrayer opened this issue Mar 25, 2019 · 0 comments
Closed

onRender called after onResize does not have new sizes for viz #59

nstrayer opened this issue Mar 25, 2019 · 0 comments

Comments

@nstrayer
Copy link
Collaborator

I believe that this could be considered a bug but perhaps I'm just not understanding the way the callbacks should be used. Basically what happens is if you add both the resize method r2d3.onResize() and also a render method r2d3.onRender() and you have resized the viz then the next time you send new data that triggers onRender() it returns the old width, and height variables to its callback function.

Here's a gif of what I'm describing

Mar 25 2019 11_20 AM - Edited - Edited

Here's a shiny app that demos what I'm talking about in as little code as I could.

app.R

library(shiny)

ui <- fluidPage(
    h3('To recreate bug'),
    tags$ul(
        tags$li('Note the size of viz provided by onRender()'),
        tags$li('Resize the app and note the new size reported by onResize()'),
        tags$li('Next press refresh button below. The size is not the new resized size, but the original onRender() size.')
    ),
    actionButton('refresh', 'Refresh Viz'),
    mainPanel( r2d3::d3Output("d3") )
)

server <- function(input, output) {
    output$d3 <- r2d3::renderD3({
        input$refresh
        r2d3::r2d3(container = 'div', script = "testing_bug.js")
    })
}

shinyApp(ui = ui, server = server)

And here's the r2d3 script:

testing_bug.js

const displayed_text = div.append('h2');

r2d3.onRender(function(data, svg, width, height, options){
  displayed_text.text(`onRender: Width: ${width}, Height: ${height}`);
});

r2d3.onResize(function(width, height){
  displayed_text.text(`onResize: Width: ${width}, Height: ${height}`);
});

Feel free to let me know if you need more info or if you have an idea of where I would dig to attempt to fix this myself.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant