In this tutorial, we will learn how to deploy a Python dashboard to the Web for Free. The tutorial uses a website named "" which lets us deploy one Web App for free. Dashboard created using Plotly & Dash is deployed on pythonanywhere.

Dash Code:

import pandas as pd
import as px
from sklearn.datasets import load_wine
from dash import Dash, html, dcc, callback
from dash.dependencies import Input, Output

### Load Data
def load_data(): 
    wine = load_wine()
    wine_df = pd.DataFrame(, columns=wine.feature_names) 
    wine_df["WineType"] = [wine.target_names[t] for t in]
    return wine_df

wine_df = load_data()
ingredients = wine_df.drop(columns=["WineType"]).columns

avg_wine_df = wine_df.groupby("WineType").mean().reset_index()

## Charts
def create_scatter_chart(x_axis="alcohol", y_axis="malic_acid", color_encode=False):
    scatter_fig = px.scatter(wine_df, x=x_axis, y=y_axis, color="WineType" if color_encode else None,
                              title="{} vs{}".format(x_axis.capitalize(), y_axis.capitalize()))
    return scatter_fig

def create_bar_chart(ingredients=["alcohol", "malic_acid", "ash"]):
    bar_fig=, x="WineType", y=ingredients, title="Avg. Ingredients per Wine Type")
    return bar_fig

## Widgets
x_axis = dcc.Dropdown(id="x_axis", options=ingredients, value="alcohol", clearable=False, style={"display": "inline-block", "width": "48%"})
y_axis = dcc.Dropdown(id="y_axis", options=ingredients, value="malic_acid", clearable=False, style={"display": "inline-block", "width": "48%"})
color_encode = dcc.Checklist(id="color_encode", options=["Color-Encode",])

multi_select = dcc.Dropdown(id="multi_select", options=ingredients, value=["alcohol", "malic_acid", "ash"], clearable=False, multi=True)

## Web App Layout
app = Dash(title="Wine Analysis")

app.layout = html.Div(
        html.H1("Wine Dataset Analysis", style={"text-align": "center"}),
        html.Div("Explore relationship between various ingredients used in creation of three different types of Wines (class_0, class_1 & class_2)", style={"text-align": "center"}),
                    x_axis, y_axis, color_encode,
                    dcc.Graph(id="scatter_chart", figure=create_scatter_chart())
            style={"display": "inline-block", "width": "48%"}
                    multi_select, html.Br(),
                    dcc.Graph(id="bar_chart", figure=create_bar_chart())
            style={"display": "inline-block", "width": "48%"}
    style={"padding": "50px"}

## Callbacks
@callback(Output("scatter_chart", "figure"), [Input("x_axis", "value"), Input("y_axis", "value"), Input("color_encode", "value")])
def update_scatter_chart(x_axis, y_axis, color_encode):
    return create_scatter_chart(x_axis, y_axis, color_encode)

@callback(Output("bar_chart", "figure"), [Input("multi_select", "value"), ])
def update_bar_chart(ingredients):
    return create_bar_chart(ingredients)

if __name__ == "__main__":



Deploy Python Dashboard to Web for Free
1 Likes1.70 GEEK