shiny icon indicating copy to clipboard operation
shiny copied to clipboard

Update getCurrentOutputInfo() on element resize or visibility change

Open cpsievert opened this issue 1 year ago • 2 comments

Currently shiny.js only sends input values tied to output values (e.g., .clientdata_output_{id}_width, etc) to the server (i.e., getCurrentOutputInfo()) when the window resizes (or if certain Bootstrap events happens). This PR leverages ResizeObserver() and IntersectionObserver() to update those relevant input values whenever the element is resized or has its visibility changed (regardless of what has caused that change)

TODO

  • ~~Investigate more why fbe9d247d493c3dd33de82e6c7320c0030415aa2 is needed~~ (it's needed because, if the output container is stretchy, the image won't know to shrink when the container shrinks since it's size is determined by the parent)

cpsievert avatar Aug 09 '22 17:08 cpsievert

I don't think https://github.com/rstudio/shiny/commit/fbe9d247d493c3dd33de82e6c7320c0030415aa2 is needed--as far as I can tell, the resize() function within image.ts just triggers the click/hover/brush handlers to clear and/or update themselves as a consequence of the image's size changing. At least that's what it's supposed to do--from my investigation in https://github.com/rstudio/shiny/pull/3683 it seems that it doesn't actually do anything useful for non-cached plots since it's triggered before the new image actually loads, and the resized image that's subsequently loaded replaces the handlers entirely (well, it did--that's one of the behaviors I change in my PR). Making it a no-op for non-cached plots didn't break anything. It does successfully resize the brush when a cached plot resizes within the bounds that don't trigger a reload, so I wasn't able to remove that path entirely.

From what it looks like to me, the change in https://github.com/rstudio/shiny/commit/fbe9d247d493c3dd33de82e6c7320c0030415aa2 just seems to briefly stretch the old plot before the re-rendered one loads--not sure if that's accomplishing anything useful.

dvg-p4 avatar Aug 15 '22 15:08 dvg-p4

(it's needed because, if the output container is stretchy, the image won't know to shrink when the container shrinks since it's size is determined by the parent)

@cpsievert what does a "stretchy output container" look like? e.g. what's an example app that doesn't resize the image properly without that https://github.com/rstudio/shiny/commit/fbe9d247d493c3dd33de82e6c7320c0030415aa2 code? (Want to make sure my PR #3683 isn't overlooking an edge case, and that it's compatible with this fix.)

dvg-p4 avatar Sep 14 '22 19:09 dvg-p4