Get startedGet started for free

Sales in a Dash app

Your Plotly graphs are making a significant impact at the company. However, it is difficult to share your work with other colleagues. You constantly have to export your graphs as images or HTML files, and when there's a new version, you need to send many emails.

It would be better if you could serve up the graphs you create as a web application. You decide to try this out on your line graph of monthly sales by country.

The ecom_sales dataset is available, and line_fig has been recreated for you.

This exercise is part of the course

Building Dashboards with Dash and Plotly

View Course

Exercise instructions

  • Create a blank Dash app object called app.
  • Set up the app layout to be a single graph component using the line_fig figure.
  • Set the app to run the server in development mode when the script is run from the console.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

from dash import Dash, dcc
import pandas as pd
import plotly.express as px
ecom_sales = pd.read_csv('/usr/local/share/datasets/ecom_sales.csv')
ecom_sales = ecom_sales.groupby(['Year-Month','Country'])['OrderValue'].agg('sum').reset_index(name='Total Sales ($)')
line_fig = px.line(data_frame=ecom_sales, x='Year-Month', y='Total Sales ($)', title='Total Sales by Month', color='Country')

# Create the Dash app
app = ____()

# Set up the layout with a single graph
app.____ = [dcc.____(
  id='my-line-graph',
  figure=line_fig)]

# Set the app to run in development mode
if __name__ == '__main__':
    app.____(debug=____)
Edit and Run Code