Get graph width and height in pixels within callback

A very similar quersion was already asked 2016 and is couldn’t be solved properly and I wonder whether the possibilities in solving have changed so far. Researching on this for a day now didn’t return anything useful.

I quote @aburato, who uses only plotly.js, while I am using dash:

My use case is: I need to display a scatter plot by querying a hufge data set on a server, like “give me all the data between 1st jan 2015 and 1st jan 2016”. This data is stored at a very high “density”, say 1 value per minute. This means that the query mentioned before would yield a HUGE amount of points (circa 550.000), which I do not want, because my chart width is, say, 1000 pixel, so to maintain readability I need the server to SAMPLE the original data and give me, say, a point for each 5 pixels (this means 200 points form the original 500.000+ )

Long story short I need to be able to know the actual plot area width so that i can compute the number of points which can fit on the screen, and query the server accordingly.

The only way I can think of is inspecting the DOM and retrieving the svg plot area width, but I’d prefer something less “hacky”

Most importantly, when creating a figure for dcc.Graph via a callback, I need to get the dimensions of the figure before I have the data for it. I cannot find a way to do this. There seems to be no way of executing javascript code within a python callback, although within js I know how to get the dimensions (via DOM/svg inspection)

The way of executing a js callback as soon as an empty figure is loaded, then get dimensions and then calling the python callback on an ‘data exchange’ div is a callback loop.

Does someone have an idea on that?