Clientside and figure update

Hello,

I am having some issues with the clientside callbacks to update figures,
in short, the code works well when the callback is server side.
When it is clientside, it “works” (no error and I can see the figure data changed) but nothing change in the dashboard.

I don’t get why the value change, but the figure stays the same, am I missing something?

It happened to change the “scene.camera.eye” to change the “view” of a 3d plot:

app.clientside_callback(
    """
    function(clk,fig){
        console.log(fig["layout"]);
        fig["layout"]["scene"]["camera"]["eye"] = {x:2, y:2, z:0.1};
        return layout
    }
    """,
    Output("graph","figure"),
    Input("testbtn","n_clicks"),
    State("graph","figure"),
    prevent_initial_call=True,
)

But it also happened with dash leaflet (to add markers on a map).
Is it normal?

Apologise in advance if I’m missing something obvious!

Best regards

Hello @VVlad,

Two things:

  • the layout you are returning in the above is going to be undefined. It needs to be defined in the callback function
  • figures cannot be modified in place, you need to set it up using JSON.parse(JSON.stringify()) and then return the new variable.
1 Like

Hello Jinnyzor,

Thanks for your help!
I kind of mess up in my message, I changed a variable before posting for “clarity” but forgot to change the “return layout” (which just make it more confusing!)

But the JSON.Parse did the trick!

Have a great day.

1 Like