I am building an app in shiny, that generates a custom svg file. When doing so, I would like to adapt the resolution to the element of the ui (in my case, a box from shinydashboard) it will be placed in.
Is there a way for my code in server.R to query the size (in pixels) of a box in the ui ?
I would imagine something like: ui$mybox$height
and ui$mybox$width
I found out that you can indeed access some information about the ui from the server.
To answer the question, you can get the width and height of an element created with plotOutput("plot1")
using session$clientData[["output_plot1_width"]]
and session$clientData[["output_plot1_height"]]
.
To get an exhaustive list of what info is available in a given session, go in debug-mode in a reactive expression in server.R
(for instance in renderText()
and type reactiveValuesToList(session$clientData)
.
If someone looking to these question you can use r2d3 and just get the size of all the container you'd like using
var width=document.getElementById(id_container).offsetWidth;
var height= document.getElementById(id_container).offsetHeight
and make the construction of your svg element depends on.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.