PyWebIO Write interactive web app in script way.

Shell IO

https://tecadmin.net/prompt-user-input-in-linux-shell-script/#

Take Input on Termianl

Let’s begin with input directly on terminal. Open a terminal on your system and type:

read x 

Here read is the Linux command and “x” is the variable, where input value will be stored.

Hit enter after typing the above command. You will see a blank line without a prompt. It means the shell is waiting for your input. Type some text and hit enter button. You will find the prompt again.

Now, verify that the input value is stored in a defined variable. To confirm it, print the variable value with the echo command.

echo $x

There is no need to define any data type for variables. Shell automatically adjusts the type based on the user input.

Lets’ go with a sample shell script to take user input.

 

PyWebIO

https://github.com/pywebio/PyWebIO

https://pywebio.readthedocs.io/en/latest/

调用python函数的方式,获取用户输入 和 输出到浏览器。(体验类似 shell )

构建简单的web应用 或者 基于浏览器的 GUI 应用, 不需要HTML JS知识。

PyWebIO provides a series of imperative functions to obtain user input and output on the browser, turning the browser into a "rich text terminal", and can be used to build simple web applications or browser-based GUI applications without the need to have knowledge of HTML and JS. PyWebIO can also be easily integrated into existing Web services. PyWebIO is very suitable for quickly building applications that do not require complex UI.

PyWebIO output demo PyWebIO input demo


特征:

  • 同步模式读取输出
  • 布局内置,不用设置
  • 更少的入侵, 修改已有代码,只需要关注输入和输出的替换,可完成代码改造
  • 支持继承到已有web框架
  • 支持 异步 和 协程
  • 支持数据可视化

Features:

  • Use synchronization instead of a callback-based method to get input
  • Non-declarative layout, simple and efficient
  • Less intrusive: old script code can be transformed into a Web application only by modifying the input and output operation
  • Support integration into existing web services, currently supports Flask, Django, Tornado, aiohttp, FastAPI framework
  • Support for asyncio and coroutine
  • Support data visualization with third-party libraries, e.g., plotly, bokeh, pyecharts.

DEMO

https://pywebio-demos.pywebio.online/

基本demo

  • BMI计算: 根据身高体重计算BMI指数
  • 聊天室: 和当前所有在线的人聊天 (不到90行代码实现)
  • Markdown实时预览: 可以实时预览的在线Markdown编辑器 (不到40行代码实现)
  • 在线五子棋游戏: 多人协作对战的五子棋游戏 (不到100行代码实现)
  • 输入演示: 演示PyWebIO输入模块的用法
  • 输出演示: 演示PyWebIO输出模块的用法
  • 更多Demo请见文档中示例代码的在线Demo

数据可视化demo

PyWebIO还支持使用第三方库进行数据可视化

  • 使用bokeh进行数据可视化 demos
  • 使用plotly进行数据可视化 demos
  • 使用pyecharts创建基于Echarts的图表 demos
  • 使用pyg2plot创建基于G2Plot的图表 demos
  • 使用cutecharts.py创建卡通风格图表 demos
出处:http://www.cnblogs.com/lightsong/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
原文地址:https://www.cnblogs.com/lightsong/p/15506842.html