Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Plotly.express graph in Dash

$
0
0

@vishnubraj wrote:

I am completely new to Dash and I am trying to create a multi line dash graph.
I am using below code, when i do core_loss_line.show() i see the graph in my browser, but i dont get any graph in Dash, it only shows the layout and no data exists. Can you please help.

#/usr/local/bin/python3
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import sqlite3
import pandas as pd
import chart_studio.plotly as py
import plotly.express as px
import plotly.graph_objs as go
conn = sqlite3.connect("/Users/vishnu/dev/scripts/insights.db")
cdf = pd.read_sql_query("select * from core_loss  where type is 'Core' order by date(date)", conn)
edf = pd.read_sql_query("select * from core_loss  where type is 'Edge' order by date(date)", conn)


core_loss_line=px.line(cdf, x='date', y='loss', color='loss')
edge_loss_line=px.line(edf, x='date', y='loss', color='loss')


#core_loss_line.show()
#edge_loss_line.show()
data = [core_loss_line, edge_loss_line]


layout = dict(
    title='Core network Loss and Outages',
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     label='1m',
                     step='month',
                     stepmode='backward'),
                dict(count=6,
                     label='6m',
                     step='month',
                     stepmode='backward'),
                dict(step='all')
            ])
        ),
        type='date'
    )
)

fig = dict(data=data, layout=layout)
app = dash.Dash(__name__)
app.layout = html.Div([
    dcc.Graph(id='my-graph', figure=fig)
])


server = app.server
if __name__ == '__main__':
    app.run_server(port=8051, debug=True)

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6271

Trending Articles