Dash is one of the most Python framework for machine learning or data science web applications. In this post, I will explain the outline for creating simple web application using Dash. I use my previous machine learning model about company’s attrition rate here as the content of the app. Goals of this project is to create a web application that can give an attrition rate’s probability of an employee based on several features that will be input by the user.
Import the Model
As I said before, we will use the previous machine learning model. It can be done using pickle module, so we don’t need to build the model again. Just extract the pickle file :) And notice that not only the model that you should save in pickle file, but also the Scaler. It because the new data still requires Scaler to remain it standardized.
Create the Layout
Layout in Dash is made using html language. I won’t make a complex application. This application designed to receive 19 feature as input from user. I classified them into two input types. The first one is input with certain range that can be deployed using
dcc.Slider, and the others is like multiple choice input that can be applied using
dcc.Dropdown module. On the first input type, some marks is provided to make it easier for user. And the last, I put this two input type in two columns so all input can be given in just one screen only.
Output is given not only to show the final result, but also show what’s value given by user on each input. To make output is out from the screen :o we use
@app.callback and state what's our output and input there.
Connect Model and Layout
I connect both of them in
def update_prediction(). Don’t forget to pre-processing the input from user to the right format we used on the machine learning model before. After it, our work is almost complete. Save it with .py extension on the same folder with model and scaler pickle file. In my case, I save it as Dash.py
Run your file.py on your cmd. It will show your localhost. Open it on your browser.
Here is the preview on my Attrition Rates App 👐
Note: All documentation can be found here. And I’m open to any critics and suggestion, just write on the comment section. Thank u and have a nice day!
 Dash Plotly