[FIXED] Server generation of Plotly figure fails

Since I needed Plotly Express (and numpty/Pandas) to generate a figure I chose to generate it on the server.
By print style debugging I have determined that the Dataframe manipulation has succeeded. However when the bar chart is generated (px.bar) I’m getting an error:

anvil.server.RuntimeUnavailableError: Downlink disconnected: 9ef5121ed39b
at Form1, line 19

Please note that the px.bar call is correct because if I use a anvil uplink script on my local system the correct graph is generated (with figure.show()).

The demo app:
https://anvil.works/build#clone:YUB2GDZENLPAVXNM=6K6YLDX75BS3XETRI3BBZCY6
contains the actual generated data.

It should generate this graph:

Any help appreciated.

Hello,

The issue is that you are using the column bin as the X coordinate and it contains inf values.

You will have to replace those with values that can be interpreted as a coordinate, or deal with them in some other way.

For example, if you want to drop rows where bin contains an inf:

df=df.replace(np.inf, np.nan)
df=df.dropna(subset=['bin'])
fig = px.bar(df, x='bin', y='delta', color='results_ok', facet_row='room')

If you deal with those infs, everything will work as expected.

1 Like

I beg to differ. Plotly handles this just fine when run standalone. It is only when run with Anvil one gets the weird error.
I don’t understand why this specific error occurs.

I don’t have all of the required answers. What I can say for sure is that it has something to do with null values.

Even the simplest example containing a null value leads to the same error:

# in the server
df=pd.DataFrame({'x': [1,2,3], 'y': [2, np.nan, 4]})
fig = px.bar(df, x='x', y='y')

It is entirely possible that there are subtle differences to how things work when comparing your local computer to the Anvil server-client relationship.

Hi @mjmare,

Yeah, that’s definitely a bug – regardless of data errors (I suspect some kind of weird numpy stuff), it definitely shouldn’t be failing with that error.

I’ve moved the thread to Bug Reports. Thanks for the nice example to reproduce the problem - that’ll make it a lot easier to fix!

1 Like

Thanks! Als thanks to @alcampopiano for the workaround.

1 Like

Hi folks,

This was an issue with transferring numpy arrays containing NaN from server to client, and it is now fixed. Thanks for your patience!

2 Likes