Today, let's share a tool for making a large data screen , Very easy to use ,100 Left and right Python The code can produce a complete data screen , And the logic of the code is very easy to understand .

PywebIO introduce

Python Middle PywebIO Modules can help developers in the absence of HTML and JavaScript It can also be built quickly Web Application or browser based GUI application ,
PywebIO It can also be combined with some common visualization modules , Make it into a large visual screen ,

Let's install the required modules first
pip install pywebio pip install cutecharts
Mentioned above cutecharts Module is Python Hand drawn visual artifact , I believe you are no stranger to this , Let's take a look at it and PywebIO
What is the effect of drawing charts in combination with modules , The code is as follows
from cutecharts.charts import Bar from cutecharts.faker import Faker from
pywebio import start_server from pywebio.output import put_html def bar_base():
chart = Bar("Bar- Basic example ", width="100%") chart.set_options(labels=Faker.choose(),
x_label="I'm xlabel", y_label="I'm ylabel") chart.add_series("series-A",
Faker.values()) put_html(chart.render_notebook()) if __name__ == '__main__':
start_server(bar_base, debug=True, port=8080)
output

The logic of the above code is not difficult to understand , Instantiate a histogram first Bar() object , Then fill in X Labels corresponding to axes and corresponding Y Value of axis , Last call PywebIO In the module put_html()
method , We'll see one URL

Enter the in the browser URL We can see the chart we have drawn . Of course cutecharts There are Page() Method to connect the charts , Make a large visual screen , The code is as follows
def bar_base(): chart = Bar("Bar- Basic example ", width="100%")
chart.set_options(labels=Faker.choose(), x_label="I'm xlabel", y_label="I'm
ylabel") chart.add_series("series-A", Faker.values()) return chart def
pie_base() -> Pie: chart = Pie(" title ", width="100%") ........ return chart def
radar_base() -> Radar: chart = Radar(" title ", width="100%") ...... return chart
def line_base() -> Line: chart = Line(" title ", width="100%") ...... return chart
def main(): page = Page() page.add(pie_base(), pie_base(), radar_base(),
line_base(), bar_base()) put_html(page.render_notebook()) if __name__ ==
'__main__': start_server(main, debug=True, port=8080)
output

PywebIO and Pyecharts Combination of

When PywebIO Module encounter Pyecharts Module time , The logic of the code is basically the same as cutecharts
Consistency of , First, instantiate a chart object , Then after adding the data and setting the style of the chart , Last call put_html() Method to render the final result in the browser
# `chart` Is an example of your chart pywebio.output.put_html(chart.render_notebook())
In this case, we call Pyecharts Composite components in , Present the completed chart separately , The code is as follows
def bar_plots(): bar = ( Bar() .add_xaxis(Faker.choose()) .add_yaxis(" business A",
Faker.values()) .add_yaxis(" business B", Faker.values())
.set_global_opts(title_opts=opts.TitleOpts(title="Grid-Bar")) ) return bar def
line_plots(): line = ( Line() .add_xaxis(Faker.choose()) .add_yaxis(" business A",
Faker.values()) .add_yaxis(" business B", Faker.values()) .set_global_opts(
title_opts=opts.TitleOpts(title="Grid-Line", pos_top="48%"),
legend_opts=opts.LegendOpts(pos_top="48%"), ) ) return line def main(): c = (
Grid() .add(bar_plots(), grid_opts=opts.GridOpts(pos_bottom="60%"))
.add(line_plots(), grid_opts=opts.GridOpts(pos_top="60%")) ) c.width = "100%"
put_html(c.render_notebook()) if __name__ == '__main__': start_server(main,
debug=True, port=8080)
output

PywebIO and Bokeh Combination of

PywebIO and Bokeh The combination of is slightly different from the above from the syntax of the code , The specific differences are as follows
from bokeh.io import output_notebook from bokeh.io import show
output_notebook(notebook_type='pywebio') fig = figure(...) ... show(fig)
For example, let's draw a simple histogram , The code is as follows
def bar_plots(): output_notebook(notebook_type='pywebio') fruits = ['Apples',
'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries'] counts = [5, 3, 4, 2,
4, 6] p = figure(x_range=fruits, plot_height=350, title="Fruit Counts",
toolbar_location=None, tools="") p.vbar(x=fruits, top=counts, width=0.9)
p.xgrid.grid_line_color = None p.y_range.start = 0 show(p) if __name__ ==
"__main__": start_server(bar_plots, debug=True, port=8080)
output

Browser based GUI application

Except will Pywebio The module is combined with common visualization modules to draw various charts , We can also use it to build a browsing based graphical interface , Let's start with the simplest application , The code is as follows
from pywebio.input import * from pywebio.output import * data = input_group(
" user data ", [ input(" May I have your name, please : ", name="name", type=TEXT), input(" Enter your age ",
name="age", type=NUMBER), radio( " Which continent ", name="continent", options=[ " Africa ",
" Asia ", " Australia ", " Europe ", " North America ", " South America ", ], ), checkbox( " User privacy regulations ", name="agreement",
options=[" agree "] ), ], ) put_text(" Table output :") put_table( [ [" name ", data["name"]],
[" Age ", data["age"]], [" position ", data["continent"]], [" regulations ", data["agreement"]], ] )
output

Some of the function methods are explained as follows :

* input(): Input of text content
* radio(): Represents a radio box
* checkbox(): Represents multiple boxes
* input_group(): Represents the input group
* put_table(): Represents the output group
* put_text(): Represents the output text

Technology
©2019-2020 Toolsou All rights reserved,
C++ of string of compare usage MySQL Basics Commonly used sentence ( Add / delete / modify query )C Language of a Gobang game implementation QT5.9 Use of learning notes QSqlQuery Method of Qt Getting Started tutorial 【 Basic controls 】QCalendarWidget calendar control java Polymorphic array of web Front end signature plug-in _signature_pad Plug in implements electronic signature function centos7 install RabbitMqspringboot use redis Experiment 4 Automated test tools - software test