Hi I am using the following table declarative widget to display a pandas 
dataframe.
When I press the button, I update the dataframe, but the urth-viz-table 
does not pick up the change. 
I have to explicitly display the dataframe in another cell, then ony the 
table is updated.

Could somebody please  suggest a solution to this?
I cannot use 'urth-viz-ipywidgets.ipynb'.

Enter code here...

import declarativewidgets as declwidgets
from ipywidgets import widgets # Widget definitions
from IPython.display import display # 
declwidgets.init()
%%html
<link rel="import" 
href="urth_components/urth-viz-table/urth-viz-table.html" 
is='urth-core-import'>
import pandas as pd
df1 = pd.DataFrame([[1,2],[3,4]], columns=['a','b'])

def update_pd_df(df, data={}):
   assert(data.get('a', None))
   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)


Enter code here...
%%html
<template is="dom-bind">
    <urth-core-dataframe id='df1' ref="df1" value="{{df1}}" 
auto></urth-core-dataframe>
    <urth-viz-table datarows="{{df1.data}}" columns="{{df1.columns}}" 
selection="{{sel1}}" rows-visible=6>
        </urth-viz-table>
</template>


Enter code here...

from IPython.display import display
button = widgets.Button(description="Click Me!")
display(button)

def on_button_clicked(b):
    global df1
    update_pd_df(df1, data={'a':1, 'b': 18})
    print("Button clicked.")

button.on_click(on_button_clicked)

Enter code here...
#this will update the widget
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/c221d32a-0415-4689-8e1d-bfbd77e52881%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to