How can I retrieve a variable from javascript to python with dash?

Viewed 123

I'm trying to display a set of columns of images in python using dash. In order to calculate how many columns I can fit in a window I would like to know the viewer width in pixels. I couldn't find a way to do this in dash so I'm trying to run javascript in the assets directory to return window.innerWidth. I think this can be done with dash_extensions but I'm not sure how to use the object returned from dash_leaflet. I'm new to javascript so tried to stick to the documentation's example as closely as possible. In my assets folder, I have the following javascript:

window.myNamespace = Object.assign({}, window.myNamespace, {  
    mySubNamespace: {  
        pointToLayer: function() {  
            return window.innerWidth
        }  
    }  
});

I'm trying to retrieve the variable from python using:

ns = Namespace("myNamespace", "mySubNamespace")
geojson = dl.GeoJSON(options=dict(pointToLayer=ns("pointToLayer")))

This apparently returns a dash_extensions.javascript.Namespace object but I'm not sure how to use it to retrieve the window width. Is there a way to do this?

0 Answers
Related