Hi, Is it possible to do the following with declarative widgets? If not do you have any suggestions?
As shown in the code below, I have a simple urth-viz-table, which displays the content of a pandas dataframe object. I have a ipywidget button, whose callback function, updates this dataframe object. But even though the dataframe object is updated the urth-viz-table never updates automatically. I have to explicitly evaluate the dataframe for the changes to percolate. -thanks -koshy On Monday, August 22, 2016 at 4:49:59 PM UTC-7, [email protected] wrote: > > Hi, > > As shown in the code below, I have a simple urth-viz-table, which > displays the content of a pandas dataframe object. I have a ipywidget > button, whose callback function, updates this dataframe object. > But even though the dataframe object is updated the urth-viz-table never > updates automatically. I have to explicitly evaluate the dataframe for the > changes to percolate. > > import declarativewidgets as declwidgets > from ipywidgets import widgets # Widget definitions > from IPython.display import display # Used to display widgets in the > notebook > declwidgets.init() > > import pandas as pd > df1 = pd.DataFrame([ > [1, 3], > [2, 4] > ], columns=["a", "b"] > ) > def update_pd_df(df, data={}): > cur_b = df.loc[df.a == data.get('a', None) ,'b'] > df.loc[df.a == data.get('a', None) ,'b'] = data.get('b', cur_b) > > %%html > > <link rel="stylesheet" type="text/css" href="bcard.css"> > <link rel="import" > href="urth_components/urth-viz-table/urth-viz-table.html" > is="urth-core-import"> > <template is="dom-bind"> > <urth-core-dataframe id="f1" ref="df1" value="{{df}}" auto > ></urth-core-dataframe> > <urth-viz-table datarows="{{ df.data }}" selection="{{sel}}" > columns="{{ df.columns }}" rows-visible=6> > </urth-viz-table> > </template> > > > > btn = widgets.Button(description='click me') > def on_btn_clicked(b): > update_pd_df(df1, data={'a': 1, 'b': 18}) > print('changing df1') > > btn.on_click(on_btn_clicked) > > display(btn) > > > df1 > > > > -- You received this message because you are subscribed to the Google Groups "Project Jupyter" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/9dd4d60d-c4ae-4bd6-8962-64b45ed49b82%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
