# Plotly express bar chart yields server error

**URL:** <https://community.plotly.com/t/plotly-express-bar-chart-yields-server-error/45608>\
**Category:** Dash Python\
**Created:** [October 1, 2020, 10:34pm UTC](https://community.plotly.com/t/plotly-express-bar-chart-yields-server-error/45608 "2020-10-01T22:34:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bastituta](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@Bastituta](https://community.plotly.com/u/Bastituta)\
**Post date:** [October 1, 2020, 10:34pm UTC](https://community.plotly.com/t/plotly-express-bar-chart-yields-server-error/45608/1 "2020-10-01T22:34:02Z")

</div>

In a dash callback I load a simple dataframe in a ploty express bar chart.  
In dataframe df I have columns ‘hour’ and ‘count’. I have 7 rows.  
When using:  
fig = px.bar(df, x=‘hour’, y=‘count’) I get a server error. Not always though.  
Anyone knows what this could be?  
With a standard fig I do not get the error.

’

---

<div class="post-metadata">

**Author:** ![matsujju](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/matsujju/32/13952_2.png) [@matsujju](https://community.plotly.com/u/matsujju)\
**Post date:** [October 2, 2020, 7:11pm UTC](https://community.plotly.com/t/plotly-express-bar-chart-yields-server-error/45608/2 "2020-10-02T19:11:19Z")

</div>

Hey @Bastituta,  
Can you show us the traceback of code? and please show the full code so that we can see what you are doing and what you are expecting?

---

<div class="post-metadata">

**Author:** ![Bastituta](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@Bastituta](https://community.plotly.com/u/Bastituta)\
**Post date:** [October 3, 2020, 7:59pm UTC](https://community.plotly.com/t/plotly-express-bar-chart-yields-server-error/45608/3 "2020-10-03T19:59:11Z")

</div>

Thanks for helping me!  
It is quite a lot of code. I took out the relevant parts.  
I do not know how to figure out what the problem is.  
Just before px.bar I am able to print things, so that works okay.  
Actually, px.bar sometimes loads, but oftne doesn’t.  
Sorry for the bad appearance, I do not know how to save code as markdown (I am not a programmer).

Here is part of the code:

# necessary input

import dash  
import dash\_core\_components as dcc  
from dash.dependencies import Input, Output, State, ALL  
import dash\_html\_components as html  
from dash.exceptions import PreventUpdate  
from app import app  
import dash\_leaflet as dl  
import plotly.express as px  
import pandas as pd  
import spatialite

# part of the layout

```
    html.Div([
        dl.Map([dl.TileLayer(url=Stadia_AlidadeSmoothDark), dl.Pane([dl.LayerGroup(id="container3", children=[])], style ={"z-index": 203}),
        dl.Pane([dl.LayerGroup(id="container2", children=[])], style ={"z-index": 202}),
        dl.Pane([dl.LayerGroup(id="container1", children=[])], style ={"z-index": 201})],
        id="map", bounds=image_bounds, style={'width': '90%', 'height': '80vh', 'margin-top': "20px", "display": "block"}),

```

# the relevant callback

@app.callback([Output(“container3”, “children”),Output(“grafiek”, “figure”),Output(“totaal”, “children”)],[Input({‘type’: ‘basismarkers’, ‘index’: ALL}, ‘n\_clicks’)])  
def select\_marker(\*args):

```
selmarkers = []
triggered = dash.callback_context.triggered

if len(triggered) > 1 or (len(triggered) == 1 and triggered[0]['value'] == 0):
    raise PreventUpdate

conn = spatialite.connect(sqlitepath)

marker_id = triggered[0]["prop_id"].split(":")[1][1:7]
df0 =pd.read_sql('''SELECT latitude, longitude from herkomsten_REF_O where PC6 = "''' + marker_id + '''"''', conn)
lat = df0.iloc[0]['latitude']
lon = df0.iloc[0]['longitude']

selmarker = dl.Marker(children=dl.Tooltip(marker_id),position=[lat,lon],icon=icon_selected,
   id="marker2" + marker_id)
selmarkers.append(selmarker)

df1 = pd.read_sql('''select * from HBs_REF_O where PC6 ="''' + marker_id + '''"''', conn)

for index, row in df1.iterrows():
    marker = dl.Marker(children=dl.Tooltip(row["PC6_2"]),position=[row["latitude"], row["longitude"]],icon=icon_destinations,
       id="marker2" + row['PC6_2'])
    selmarkers.append(marker)

df = pd.read_sql('''select * from tijden_REF_O where PC6 ="''' + marker_id + '''"''', conn)

try:
    totaal = df.groupby(['PC6'])['count'].sum().iloc[0]
    tot = 'Totaal voor ' + marker_id + ': {}'.format(totaal)
except:
    tot =''

# from here it goes sometimes wrong
fig = px.bar(df0, x='uur', y='count', color = 'typerit', title= 'Aankomsten en vertrekken', range_x=[0,23],
             labels={"count": "ritten" }, hover_data=['count'], barmode = 'stack')

del df0, df1, df

conn.close()
return selmarkers, fig, tot

```

The relevant dataframe looks like this:  
df = pd.read\_sql(’’‘select \* from tijden\_REF\_O where PC6 ="’’’ + marker\_id + ‘’’"’’’, conn)

```
index PC6 uur count typerit

```

0 647 7382SB 13 1 vertrek  
1 648 7382SB 14 14 vertrek  
2 649 7382SB 15 4 vertrek  
3 650 7382SB 16 26 vertrek  
4 651 7382SB 17 17 vertrek  
5 1492 7382SB 7 1 aankomst  
6 1493 7382SB 8 1 aankomst  
7 1494 7382SB 9 48 aankomst

---

<div class="post-metadata">

**Author:** ![matsujju](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/matsujju/32/13952_2.png) [@matsujju](https://community.plotly.com/u/matsujju)\
**Post date:** [October 4, 2020, 8:07am UTC](https://community.plotly.com/t/plotly-express-bar-chart-yields-server-error/45608/4 "2020-10-04T08:07:40Z")

</div>

I was asking for error you get.

---

<div class="post-metadata">

**Author:** ![Bastituta](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@Bastituta](https://community.plotly.com/u/Bastituta)\
**Post date:** [October 5, 2020, 9:00am UTC](https://community.plotly.com/t/plotly-express-bar-chart-yields-server-error/45608/5 "2020-10-05T09:00:01Z")

</div>

Thanks!  
I do not know how to find the error. Don’t know how to open the browser’s console.  
I get the following message:  
 ![image.png](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/3/3e4073f01c90362c2eb515fe439ece12a9dc9245.png)
