Pie chart with drop down list and date picker range in plotly dash

Pie chart with drop down list and date picker range in plotly dash

Create pie chart with drop down list and date picker range in plotly dash using the plotly and dash web library.

Inputs: Drop down list and date picker range

Create this pie chart with drop down list and date picker range in plotly dash. There are two input components in this dashboard that are drop down list and date picker range. We can filter the data from the data source for the specific date using the date picker range. Pie chart gets update when input values change in the drop down list and date picker range in this simple dash app.

See below how this dashboard work?

Layout of date picker range

Date picker range is very useful component of the dash library. There are many parameters for this input component. Most of them I have used below. In lines 22 and 23, I have entered start date and end date parameters. These two parameters use in callback function as inputs to filter the specific date from the data frame.

Pie chart

I have created four data frames for this pie chart to display data on four slices. See below in the code template from lines 6 to 28. In these data frames, I have calculated the total values for each slice and then filter that values with drop down list and date picker range. In lines 10, 16, 22 and 28, you can see in the below code template, I have filtered the data from the data frames using the id of drop down list to get values for specific country from the corresponding column and I have inserted between function to get values between two dates from the data frames.

Text template

Text template is used to format data on bars, markers, pie chart and donut chart slices. You can check below in the line 39, I have used label, value and percent to format on pie chart.

Download the full code and CSV data file and learn more about plotly dash on Udemy.


If you have any problem in learning above code, please comment in the comment box. I will help you as soon as possible.


Recommended For You

About the Author: Mubeen Ali

I am passionate about learning Dash. Dash is a python framework that creates beautiful web based data visualization dashboards.