@@ -21,23 +21,27 @@ but Python 3 is strongly recommended for new applications. In addition
21
21
to Python throughout this tutorial we will also use the following
22
22
[ application dependencies] ( /application-dependencies.html ) :
23
23
24
- * [ Flask] ( /flask.html ) web framework, 0.12
25
- * [ Bokeh] ( /bokeh.html ) data visualization library, version 0.12.5
24
+ * [ Flask] ( /flask.html ) web framework,
25
+ [ version 0.12.2] ( https://github.com/pallets/flask/releases/tag/0.12.2 )
26
+ * [ Bokeh] ( /bokeh.html ) data visualization library,
27
+ [ version 0.12.5] ( https://github.com/bokeh/bokeh/releases/tag/0.12.5 )
26
28
* [ pandas] ( /pandas.html ) data structures and analysis library,
27
- version 0.20.1
29
+ [ version 0.20.1] ( https://github.com/pandas-dev/pandas/releases/tag/v0.20.1 )
28
30
* [ pip] ( https://pip.pypa.io/en/stable/ ) and
29
31
[ virtualenv] ( https://virtualenv.pypa.io/en/latest/ ) , which come
30
- packaged with Python 3, to install and isolate the Flask and Bokeh
31
- libraries from any other Python projects you might be working on
32
+ packaged with Python 3, to install and isolate the Flask, Bokeh,
33
+ and pandas libraries from any other Python projects you might be
34
+ working on
32
35
33
36
If you need help getting your
34
37
[ development environment] ( /development-environments.html ) configured
35
38
before running this code, take a look at
36
39
[ this guide for setting up Python 3 and Flask on Ubuntu 16.04 LTS] ( /blog/python-3-flask-green-unicorn-ubuntu-1604-xenial-xerus.html )
37
40
38
41
All code in this blog post is available open source under the MIT license
39
- on GitHub under the blog-code-examples repository. Use it and abuse it
40
- as you like for your own applications.
42
+ on GitHub under the
43
+ [ bar-charts-bokeh-flask-python-3 directory of the blog-code-examples repository] ( https://github.com/fullstackpython/blog-code-examples ) .
44
+ Use the source code and abuse it as you like for your own applications.
41
45
42
46
43
47
## Installing Bokeh and Flask
@@ -93,3 +97,73 @@ We are going to first code a basic Flask application then add our bar
93
97
chart to the rendered page.
94
98
95
99
100
+ ` app.py ` :
101
+
102
+ ``` python
103
+ from flask import Flask, render_template
104
+
105
+
106
+ app = Flask(__name__ )
107
+
108
+
109
+ @app.route (" /<int:bars_count>/" )
110
+ def chart (bars_count ):
111
+ return render_template(" chart.html" , bars_count = bars_count)
112
+
113
+
114
+ if __name__ == " __main__" :
115
+ app.run(debug = True )
116
+ ```
117
+
118
+ ...explain code...
119
+
120
+ ` templates/chart.html ` :
121
+
122
+ ```
123
+ <!DOCTYPE html>
124
+ <html>
125
+ <head>
126
+ <title>Bar charts with Bokeh!</title>
127
+ </head>
128
+ <body>
129
+ <h1>Bugs found over the past {{ bars_count }} days</h1>
130
+ </body>
131
+ </html>
132
+ ```
133
+
134
+ Short explanation of above HTML.
135
+
136
+ ```
137
+ $(barchart) python app.py
138
+ ```
139
+
140
+ Go to "localhost:5000" in your web browser.
141
+
142
+ ...Screenshots of it working...
143
+
144
+
145
+ ## Generating the Bar Chart
146
+
147
+
148
+
149
+ ## What's next?
150
+ Nice work creating a nifty configurable bar chart in Bokeh! Next
151
+ up you can modify the color scheme, change the input data source or try
152
+ to create other types of charts.
153
+
154
+ There is a lot more than Bokeh can do, so be sure to check out the
155
+ [ official project documentation] ( http://bokeh.pydata.org/en/latest/ ) ,
156
+ [ GitHub repository] ( https://github.com/bokeh/bokeh ) ,
157
+ the [ Full Stack Python Bokeh page] ( /bokeh.html ) or take a look at
158
+ [ other topics on Full Stack Python] ( /table-of-contents.html ) .
159
+
160
+ Questions? Let me know via
161
+ [ a GitHub issue ticket on the Full Stack Python repository] ( https://github.com/mattmakai/fullstackpython.com/issues ) ,
162
+ on Twitter
163
+ [ @fullstackpython ] ( https://twitter.com/fullstackpython )
164
+ or [ @mattmakai ] ( https://twitter.com/mattmakai ) .
165
+
166
+ See something wrong in this blog post? Fork
167
+ [ this page's source on GitHub] ( https://github.com/mattmakai/fullstackpython.com/blob/master/content/posts/170524-bar-charts-bokeh.markdown )
168
+ and submit a pull request.
169
+
0 commit comments