Last active
June 12, 2021 14:41
-
-
Save kylebutts/0cc3045b964f59565f37f7078777409e to your computer and use it in GitHub Desktop.
Shiny - Window Size: gets window size and stores in input$dimension ([1] = width, [2] = height)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # From https://stackoverflow.com/questions/36995142/get-the-size-of-the-window-in-shiny | |
| # https://stackoverflow.com/a/37060206 | |
| tags$head(tags$script(' | |
| var dimension = [0, 0]; | |
| $(document).on("shiny:connected", function(e) { | |
| dimension[0] = window.innerWidth; | |
| dimension[1] = window.innerHeight; | |
| Shiny.onInputChange("dimension", dimension); | |
| }); | |
| $(window).resize(function(e) { | |
| dimension[0] = window.innerWidth; | |
| dimension[1] = window.innerHeight; | |
| Shiny.onInputChange("dimension", dimension); | |
| }); | |
| ')) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Include the above in UI declaration