plotly / Dash.jl

Dash for Julia - A Julia interface to the Dash ecosystem for creating analytic web applications in Julia. No JavaScript required.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] Is Scattermapbox layers supported?

hs-ye opened this issue · comments

Hi team,

I would like to do something like this https://plotly.com/python/mapbox-layers/#openstreetmap-tiles-no-token-needed

Is this supported current dash.jl interface? I can see that there are references to inputting a mapboxAccessToken in the docstrings for dcc_graph, but unsure if full Julia support has caught up? There is obviously no equivalent for plotly express package in Julia just yet.

Here's what I've come up with so far:

app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])

app.layout = html_div() do
        html_h1("Test Mapbox Plot"),
        dcc_graph(
            id = "graph-mapbox-plot",
            figure = (
                data = [
                    (lon = [145.1466232, 145.1489419, 145.1489618], lat = [-37.8868434, -37.8871689, -37.8870577], type = "scattermapbox", name = "m1", mode = "markers"),
                ],
                layout = (title = "mapbox plot")
            )
        )
    end

Which obviously didn't work.

As there is no Plotly express, I'm also reading from here that I may need to construct this manually using the Plotly graphs interface, but also not sure if this pattern is the same for Dash.jl?

If the feature isn't there yet I may just stick to Python to now, but it would be cool to be able to do this in Julia.

Any help would be appreciated!

Updated from me - I have discovered that the config I was missing is to pass through the mapboxAccessToken as a named tuple, which is because of the JSON2 backend being used for the configs...

So the code below now works and I am able to see the scattermapbox layer and also the points plotted on it. However the plot isn't zoomed in over the bounds, but rather starts as the map of the entire world, and each time I re-plot new points it also resets the map view.

Ideally I want to do this, and I can see that the code for a 'fitbound' config option is in the plotlyJS bundled with dash.jl

My more general question is: how do I access these config options in the underlying plotlyJS?

Working scattermapbox trace plot:

app.layout = html_div() do
        html_h1("Test Mapbox Plot"),
        dcc_graph(
            id = "graph-mapbox-plot",
            figure = (
                data = [
                    (lon = [145.1466232, 145.1489419, 145.1489618], lat = [-37.8868434, -37.8871689, -37.8870577], type = "scattermapbox", name = "m1", mode = "markers"),
                ],
                layout = (title = "mapbox plot")
            ),
          config = (mapboxAccessToken="pk.xxxxxx.xxxx",)
        )
    end

Sorry for the delay! This is possible and we're working on documenting it at http://juliaplots.org/PlotlyJS.jl/stable/examples/maps/.

We'll close the issue when Mapbox + Julia is documented for PlotlyJS.jl.

Thanks guys, appreciate the update.
I've found that most of the python docs/interface into plotlyJS works for Julia (assuming it's a port)

For anyone that is wondering, for scattermapbox plots all these figure>layout options under dcc_graph are working, just have to pass them in as the correct container types. This took a bit of experimentation and would be good to have documented:

figure =(
        ... # other options ommitted
        layout = (title = "Chart title", mapbox = Dict("zoom"=>16, "center"=>(lon=148.4, lat=-37.7), "style"=>"open-street-map"))  # note the mix of dict vs namedTuples here
    )

Hi @spcogg thanks for the work here!

We've recently put in some work to make PlotlyJS.jl much more capable (read, "much more similar to plotly express")

The documentation for this should be out very shortly, but in the meantime I'm happy to give you some tips on how to use it.

Would you mind posting a minimal example that you got working and I'll see if I can help simplify it by tapping in to PlotlyJS.jl?

Thanks!

sorry for the delay - are you guys still interested in this? It'll take a little while but happy to dig it up if it's helpful

Thanks for being willing. If you are good, so are we!

here it is:


using Dash
using DashHtmlComponents
using DashCoreComponents

app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])

app.layout = html_div() do
        html_h1("Test Mapbox Plot"),
        dcc_graph(
            id = "graph-mapbox-plot",
            figure = (
                data = [
                    (lon = [145.1466232, 145.1489419, 145.1489618], lat = [-37.8868434, -37.8871689, -37.8870577], type = "scattermapbox", name = "m1", mode = "markers"),
                ],
                layout = (title = "Chart title", mapbox = Dict("zoom"=>8, "center"=>(lon=145.14662, lat=-37.88), "style"=>"open-street-map"))  # note the mix of dict vs namedTuples here
            )
        )
    end

run_server(app, "0.0.0.0", 8080)

Which should give you a scattermapbox layer with dots plotted over it, and also starting off centred and zoomed correctly.

(Actually after digging through my notes, just had to put all the above posts together, which I should have done to begin with...)