Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Application Hangs when adding 40+ Traces

Hi All,

I’m designing a time-series data analysis application using Dash+Plotly. Here’s my setup version(s) :

dash - 1.14.0
plotly - 4.9.0
dash_html_components - 1.0.3
dash_core_components - 1.10.2

I have a column which has nearly 40-70 unique categories. I want to create a scatter plot where I need a trace for each category. I tried sub-dividing the data based on category, and tried adding trace for each of them. Basically, a single figure with 40-70 traces. But, the application gets crashed if I do this. I know there is a way by which we can color map the markers, but I don’t know how. Plus, the no of entries in this column changes dynamically, depending on the input data. Can someone help me how I could achieve this?

Here is a small snippet of my code:

import pandas as pd
import numpy as np
import plotly.graph_objects as go

fig = go.Figure()
df = pd.read_csv(r'data.csv')
colors = df.Colors.unique().tolist()     # Categorical column which has 40-70 unique values

for c in colors:
    temp = df[df.TCID.isin([c])]
    fig.add_trace(
        go.Scatter(
            x = df['X'],
            y = df['Y'],
            mode = 'markers',
            name = thread,
            marker = dict(
                size=7,
                line = dict(
                    width = 1,
                    color = 'DarkSlateGrey')
            )
        )
    )

fig.update_layout(title_text = 'Sample Plot')
fig.write_html('plot.html', auto_open=True)