taipy icon indicating copy to clipboard operation
taipy copied to clipboard

Need to get several indexes when doing a box/ lasso selection from a plotly graph

Open vhfgosselin opened this issue 1 year ago • 3 comments

Description When using the new feature to integrate plotly charts, we do get the index of the selected point on the chart. However, when performing a box or lasso selection, the selected_state is empty instead of returning a list of indexes corresponding to the selected points.

How to reproduce You can check using the following code below

  • A code fragment
    from taipy.gui import Gui 
    import plotly.express as px
    
    df = px.data.gapminder()
    df_first = df[df['year']==2007].reset_index(drop=True)
    bubble_fig = px.scatter(df_first, x="gdpPercap", y="lifeExp",size="pop", hover_name="country", log_x=True, size_max=60)
    
    selected_state = []
    
    def on_change(state,var,val):
     print("val = ", val)
     if var == 'selected_state':
        print(state.selected_state)
        print("selected state", val, "row:", state.df_first.iloc[val])
    
    md = """
    <|chart|figure={bubble_fig}|selected={selected_state}|>
      ```
    Gui(md).run(port=4563)
    
    
    

Expected behavior selected_state variable shouldn't be empty, it should contain a list of indexes corresponding to the selected points.

Runtime environment Taipy develop branch Windows 11

vhfgosselin avatar Jan 17 '24 15:01 vhfgosselin

Works for me image

selected state [103, 104, 109] 
row:           country continent  year  lifeExp       pop    gdpPercap iso_alpha  iso_num
103      Portugal    Europe  2007   78.098  10642836  20509.64777       PRT      620
104   Puerto Rico  Americas  2007   78.746   3942491  19328.70901       PRI      630
109  Saudi Arabia      Asia  2007   72.777  27601038  21654.83194       SAU      682

FredLL-Avaiga avatar Jan 18 '24 08:01 FredLL-Avaiga

What I see is that there are 2 events fired on box selection:

  • the first one contains the list of indexes
  • the second one is empty ...

FredLL-Avaiga avatar Jan 18 '24 08:01 FredLL-Avaiga

Yes, not sure why we get 2 events here. This happens for both box and lasso selection.

vhfgosselin avatar Jan 18 '24 09:01 vhfgosselin