Create horizontal bar chart with slider in plotly dash

Create horizontal bar chart with slider in plotly dash

Create horizontal bar chart with slider in plotly dash using an interactive plotly data visualization library and dash web library.

Inputs: Slider and radio items

I have created horizontal bar chart with slider in plotly dash. Slider extract data from the data frames for top 10 values for the specific period. There are two charts in this dash app. These two charts connect with radio items. Selecting any radio item, dash app displays corresponding chart. Values change dynamically on these two charts. View below dash app.

See below how this dashboard work?

Layout of radio items and graphs

Create layout of radio items inside html div of graph to show radio items inside grid of horizontal bar chart. See below in the code template.

Horizontal Bar Chart 1

Create callback of first horizontal bar chart in this plotly dash app. First of all, create data frames for two horizontal bar chart below the def function. See below lines 6 to 8 in the code template. After that insert if statement to connect first horizontal bar chart with radio items. This horizontal bar chart displays deaths data for top ten countries for each selected period. Use terr2 data frame in x and y parameters to filter data from the data frame terr1. Use margin property in the layout of chart to display full text on the y-axis. See below line 49 in the code template.

Create horizontal bar chart with slider in plotly dash

Horizontal Bar Chart 2

Create data and layout sections of second horizontal bar chart below the first horizontal bar chart. Type elif statement to connect second horizontal bar chart with radio item. See below line 1 in the code template. Use terr3 data frame to filter data from the data frame terr1.

Create horizontal bar chart with slider in plotly dash

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.