Adding trace to dash plotly express line graph

Hello Everyone,

Myself Sruthin. I have been working on the Dash library for one month for building the dashboard for my application using Python.
I have been facing one issue for few days.
I need help with my issue, if anyone can give a solution for this problem, it would be very helpful for me.!

In the below code, i was adding a scatter plot trace to the line graph of Plotly express.
I don’t know what is the mistake in the code, only line graph is visualized in the final output graph, but not the scatter plots

The below graph represents the final graph that I wanted, but the only line graph is visualized but not those scatter points.

But when I use the same data to plot the graph using Plotly but not dash, I’m getting the final graph.

So the main problem here is with the Dash. Can anyone figure out what was the problem for using the code in Dash, why can’t get the graph in Dash?

code|690x241

Any help is highly appreciated
Thanks in advance

Hi there,

I cannot reproduce your error. Here’s my code:

from dash import Dash
import dash_core_components as dcc
import plotly.express as px
import plotly.graph_objects as go

df = px.data.iris()

app = Dash(__name__)

fig = px.line(
    df,
    x="sepal_length",
    y="petal_length"
)

fig.add_trace(
    go.Scatter(
        x=df["sepal_length"],
        y=df["petal_length"],
        mode="markers"
    )
)

app.layout = dcc.Graph(figure=fig)

if __name__ == "__main__":
    app.run_server(debug=True)

Perhaps there is another error in your application… Did you fix this issue already?

Please also be mindful that it is easier to paste the code in Markdown than in a screenshot, so others can copy it if needed (plus it is easier to read).