jupyter / declarativewidgets

[RETIRED] Jupyter Declarative Widget Extension
http://jupyter.org/declarativewidgets/docs.html
Other
120 stars 38 forks source link

Forcing an urth-viz-bar widget to re-render from a python function #529

Closed Etiennepi closed 7 years ago

Etiennepi commented 7 years ago

Hi, I'm currently working on a dynamic dashboard that allows the user to select some parameters through polymer components. Those parameters are then used to run queries on a remote database, which contains the data to be displayed by different urth-viz components.

The issue I'm running into is that unless the data is available before a urth-viz component is initialized, I can't seem to get the chart display properly. If the dataframe doesn't exist and the function bound to it doesn't return a dataframe with fake data, I won't get any graphs at all. If I return fake data, It'll display a graph, but I won't be able to update it when calling invoke on the function's id. Doing this works on a table however.

MattKravetz commented 7 years ago

Hi Etiennepi,

Have you tried setting the "auto" parameter in the urth-core-function that provides the data?

I have a similar dashboard where users can specify a query that drives a chart. The query is passed to a urth-core-function, which then passes parameters into my python function that returns the formatted pandas dataframe. The chart data is bound to the return value of this function, so it updates automatically whenever the function is invoked. Since the "auto" parameter is set in the urth-core-function, the python function is being evoked whenever the input parameters change. See below:

image

lbustelo commented 7 years ago

@Etiennepi Another way to help in these types of problems is to wrap the chart element with a <template is='dom-if'> element. So if the {{var}} that would hold the data is not set, it will not even render the chart.

Etiennepi commented 7 years ago

Hey, thanks for the tips. I managed to fix this issue by having the function return a bogus dataframe with the right number of columns/rows when the the query hasn't been run. One the queries are run, I then invoke each of the functions manually with functionid.invoke(). With all the possible solutions to this, I definitely think this could be closed.