{"id":18273,"date":"2020-08-31T20:02:30","date_gmt":"2020-08-31T20:02:30","guid":{"rendered":"https:\/\/ittutorial.org\/?p=18273"},"modified":"2020-08-31T20:31:13","modified_gmt":"2020-08-31T20:31:13","slug":"python-flask-dash-dataframe-to-data-table-web-app","status":"publish","type":"post","link":"https:\/\/ittutorial.org\/python-flask-dash-dataframe-to-data-table-web-app\/","title":{"rendered":"Python Flask &amp; Dash Dataframe to Data Table (Web App)"},"content":{"rendered":"<p>Hi everyone, in this article i&#8217;ll show you how to display dataframe on web. Libraries required for this; Flask and dash<\/p>\n<p>I mostly use Pycharm as an IDE, and I will do these examples in PyCharm.<\/p>\n<p>First, let&#8217;s create a Flask project,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-18274\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_1-1.png\" alt=\"\" width=\"1012\" height=\"580\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_1-1.png 1012w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_1-1-300x172.png 300w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_1-1-768x440.png 768w\" sizes=\"auto, (max-width: 1012px) 100vw, 1012px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>After the project is created, you will see a screen like the one below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-18275\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_2-2.png\" alt=\"\" width=\"1866\" height=\"792\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_2-2.png 1866w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_2-2-300x127.png 300w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_2-2-1024x435.png 1024w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_2-2-768x326.png 768w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_2-2-1536x652.png 1536w\" sizes=\"auto, (max-width: 1866px) 100vw, 1866px\" \/><\/p>\n<p>For testing, let&#8217;s run the project and go to <strong>localhost:5000<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-18276\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_3-2.png\" alt=\"\" width=\"980\" height=\"486\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_3-2.png 694w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_3-2-300x149.png 300w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><\/p>\n<p>Now we start the important part, dash allows us to show the dataframe as a table in our web application.\u00a0 It also contains many features such as filtering and visualization on the table.<\/p>\n<p>Install the dash library.<\/p>\n<pre>pip install dash<\/pre>\n<p>Then add this library to our app.py file.<\/p>\n<pre>import dash_table<\/pre>\n<p>Using flask and dash together can sometimes seem confusing, First, I share the entire code block and then I&#8217;ll start explaining.<\/p>\n<pre>from flask import Flask\r\nimport pandas as pd\r\nimport dash_table\r\nimport dash\r\n\r\nserver = Flask(__name__)\r\n\r\n@server.route('\/')\r\ndef hello_world():\r\nreturn 'Hello World!'\r\n\r\nDataFrame = pd.read_csv(\"https:\/\/raw.githubusercontent.com\/plotly\/datasets\/master\/solar.csv\")\r\n\r\napp = dash.Dash(\r\n__name__,\r\nserver=server,\r\nroutes_pathname_prefix='\/dash\/')\r\n\r\napp.layout = dash_table.DataTable(\r\nid = \"table\",\r\ndata=DataFrame.to_dict('records'),\r\ncolumns=[{'id': c, 'name': c} for c in DataFrame.columns],\r\npage_action='none',\r\nstyle_table={'height': '300px', 'overflowY': 'auto'}\r\n)\r\n\r\nif __name__ == '__main__':\r\napp.run_server()<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-18277\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_5-1.png\" alt=\"\" width=\"1242\" height=\"883\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_5-1.png 1242w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_5-1-300x213.png 300w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_5-1-1024x728.png 1024w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_5-1-768x546.png 768w\" sizes=\"auto, (max-width: 1242px) 100vw, 1242px\" \/><\/p>\n<p><span style=\"color: #339966\">1- )\u00a0 The code block in the green box is the area where our flask application first started.<\/span><\/p>\n<p><span style=\"color: #3366ff\">2- )\u00a0 The code block in the blue box is the necessary configurations of our dash application. When we go to the <strong>\/dash<\/strong> area, we will see our table. We can give this part the name we want<\/span><\/p>\n<p><span style=\"color: #800080\">3- ) We specify what we want to do with the code block dash in the red box. dash has too many components, we will create a data table in this example. In the future, we will make a visualization with the app.layout part in the examples.<\/span><\/p>\n<p>Finally, let&#8217;s run our application and go to <strong>127.0.0.1\/dash<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-18279\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_4.png\" alt=\"\" width=\"1601\" height=\"325\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_4.png 1916w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_4-300x61.png 300w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_4-1024x208.png 1024w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_4-768x156.png 768w, https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/Screenshot_4-1536x313.png 1536w\" sizes=\"auto, (max-width: 1601px) 100vw, 1601px\" \/><\/p>\n<p>Everything seems right.<\/p>\n<p>See you in the next article \ud83d\ude42<\/p>\n<p>&nbsp;<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"JPXwM7f9GL\"><p><a href=\"https:\/\/ittutorial.org\/decathlon-product-capturing-using-python-beautifulsoup\/\">Decathlon Product Capturing using Python (Beautifulsoup)<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Decathlon Product Capturing using Python (Beautifulsoup)&#8221; &#8212; IT Tutorial\" src=\"https:\/\/ittutorial.org\/decathlon-product-capturing-using-python-beautifulsoup\/embed\/#?secret=gdRkWrSmnk#?secret=JPXwM7f9GL\" data-secret=\"JPXwM7f9GL\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi everyone, in this article i&#8217;ll show you how to display dataframe on web. Libraries required for this; Flask and dash I mostly use Pycharm as an IDE, and I will do these examples in PyCharm. First, let&#8217;s create a Flask project, &nbsp; After the project is created, you will see a screen like the &hellip;<\/p>\n","protected":false},"author":67,"featured_media":18283,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7228],"tags":[12844,12845,12838,12842,12843,6697,12841,12839,12840],"class_list":["post-18273","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-python","tag-dataframe-to-data-table","tag-dataframe-to-data-table-flask","tag-flask","tag-flask-dash","tag-flask-dataframe-to-table","tag-python","tag-python-dash","tag-python-flask","tag-python-flask-dash"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/ittutorial.org\/wp-content\/uploads\/2020\/08\/indir-1.png","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/18273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/users\/67"}],"replies":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/comments?post=18273"}],"version-history":[{"count":5,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/18273\/revisions"}],"predecessor-version":[{"id":18284,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/18273\/revisions\/18284"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media\/18283"}],"wp:attachment":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media?parent=18273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/categories?post=18273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/tags?post=18273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}