Coder Social home page Coder Social logo

pywebio / pywebio Goto Github PK

View Code? Open in Web Editor NEW
4.3K 53.0 374.0 11.47 MB

Write interactive web app in script way.

Home Page: https://pywebio.readthedocs.io

License: MIT License

Python 73.95% JavaScript 0.14% CSS 1.43% HTML 1.01% Shell 0.03% TypeScript 23.44%
pywebio

pywebio's Introduction

PyWebIO

Write interactive web app in script way.

Percy visual test Code coverage Jsdelivr hit count Documentation Status Package version Python Version
License
[Document] | [Demos] | [Playground] | [Why PyWebIO?]

English | 中文

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

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.

Installation

Stable version:

pip3 install -U pywebio

Development version:

pip3 install -U https://github.com/pywebio/PyWebIO/archive/dev-release.zip

Prerequisites: PyWebIO requires Python 3.5.2 or newer

Quickstart

Hello, world

Here is a simple PyWebIO script to calculate the BMI:

from pywebio.input import input, FLOAT
from pywebio.output import put_text

def bmi():
    height = input("Your Height(cm):", type=FLOAT)
    weight = input("Your Weight(kg):", type=FLOAT)

    BMI = weight / (height / 100) ** 2

    top_status = [(14.9, 'Severely underweight'), (18.4, 'Underweight'),
                  (22.9, 'Normal'), (27.5, 'Overweight'),
                  (40.0, 'Moderately obese'), (float('inf'), 'Severely obese')]

    for top, status in top_status:
        if BMI <= top:
            put_text('Your BMI: %.1f, category: %s' % (BMI, status))
            break

if __name__ == '__main__':
    bmi()

This is just a very simple script if you ignore PyWebIO, but using the input and output functions provided by PyWebIO, you can interact with the code in the browser [demo]:

PyWebIO demo

Serve as web service

The above BMI program will exit immediately after the calculation, you can use pywebio.start_server() to publish the bmi() function as a web application:

from pywebio import start_server
from pywebio.input import input, FLOAT
from pywebio.output import put_text

def bmi(): # bmi() keep the same
    ...  

if __name__ == '__main__':
    start_server(bmi, port=80)

Integration with web framework

To integrate a PyWebIO application into Tornado, all you need is to add a RequestHandler to the existing Tornado application:

import tornado.ioloop
import tornado.web
from pywebio.platform.tornado import webio_handler

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

if __name__ == "__main__":
    application = tornado.web.Application([
        (r"/", MainHandler),
        (r"/bmi", webio_handler(bmi)),  # bmi is the same function as above
    ])
    application.listen(port=80, address='localhost')
    tornado.ioloop.IOLoop.current().start()

Now, you can open http://localhost/bmi for BMI calculation.

For integration with other web frameworks, please refer to document.

Demos

  • Basic demo : PyWebIO basic input and output demos and some small applications written using PyWebIO.
  • Data visualization demo : Data visualization with the third-party libraries, e.g., plotly, bokeh, pyecharts.

Links

pywebio's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pywebio's Issues

[Feature request] set_env 支持移动端防止休眠

当移动端访问时,休眠会导致websocket断开

目前通过run_js功能,可以通过播放空音频的方式来防止移动设备休眠

个人觉得这是一个值得在set_env中,官方实现的功能

Flask 2 integration

Flask 2.0 has been released, and routing has been upgraded.
Is there any needs for us to upgrade the documentation of PyWebIO?

无法运行 README 中计算 BMI 的示例

PyWebIO 版本:

PS D:\Temp\test-pywebio> pip show pywebio
Name: pywebio
Version: 1.0.1

Python 版本:

PS D:\Temp\test-pywebio> python --version
Python 3.8.3

报错信息:

PS D:\Temp\test-pywebio>  & 'C:\Users\admin\Anaconda3\python.exe' 'c:\Users\admin\.vscode\extensions\ms-python.python-2020.12.424452561\pythonFiles\lib\python\debugpy\launcher' '60851' '--' 'd:\Temp\test-pywebio\bmi.py'
Exception in thread Tornado-server:
Traceback (most recent call last): 
  File "C:\Users\admin\Anaconda3\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\admin\Anaconda3\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\admin\Anaconda3\lib\site-packages\pywebio\platform\tornado.py", line 296, in server_thread
    server, port = _setup_server(webio_handler=SingleSessionWSHandler, port=port, host='localhost')
  File "C:\Users\admin\Anaconda3\lib\site-packages\pywebio\platform\tornado.py", line 157, in _setup_server
    server = app.listen(port, address=host)
  File "C:\Users\admin\Anaconda3\lib\site-packages\tornado\web.py", line 2116, in listen
    server.listen(port, address)
  File "C:\Users\admin\Anaconda3\lib\site-packages\tornado\tcpserver.py", line 152, in listen
    self.add_sockets(sockets)
  File "C:\Users\admin\Anaconda3\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
    self._handlers[sock.fileno()] = add_accept_handler(
  File "C:\Users\admin\Anaconda3\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "C:\Users\admin\Anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 100, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "C:\Users\admin\Anaconda3\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError

Attempting to render an example

Hello,
I came across your package today. Looks like its quite intuitive. I just wanted to give it a shot and I tried the following based on an article from @khuyentran, however I just run into an error and the app never renders. Could you point me in a helpful direction ?

import pandas as pd
from pywebio.input import file_upload
from pywebio.output import put_table, put_loading
from pywebio import start_server
import csv
import re


def app():
    file = file_upload(label='Upload your CSV file', accept='.csv')
    content = file['content'].decode('utf-8').splitlines()

    df = content_to_pandas(content)
    create_profile(df)


def create_profile(df: pd.DataFrame):
    put_table(df.to_dict())

def content_to_pandas(content: list):
    with open("tmp.csv", "w") as csv_file:
        writer = csv.writer(csv_file, delimiter='\t')
        for line in content:
            writer.writerow(re.split('\s+', line))
    return pd.read_csv("tmp.csv")


if __name__ == '__main__':
    start_server(app, port=37791, debug=True)

image

Pyinstaller 打包问题

BUG描述
Pyinstaller 打包时 静态资源 pywebio.html 未加载到打包目录下
手动添加后运行正常

环境信息

  • 操作系统: Win 10 x64
  • 浏览器及版本: Chrome 88.0.4324.104
  • Python版本: 3.7.9
  • PyWebIO版本: 1.0.3

LaTeX or MathJaX support?

Do you have any plan in the roadmap to support the LaTeX math formula inside a markdown string?
This is one of the attractive things for Streamlit.
Generally, it is done with the $...$ end markers.

Error after configuring nginx

I configured nginx according to the example and now it can access the port I'm running the python script on but it gives me this error. What is the cause of this error?

Screen Shot 2021-04-13 at 6 19 57 PM

I'm calling my app function like this:

if __name__ == '__main__':
    start_server(schema_app, port=36535, debug=True)

感觉"交互“属性有点过于强了……能否 Input 提交后,不要就那么消失啊……

如题。

这个有点过于repl了。问题是,cli下的repl,可以清楚看到自己刚才的输入。这个库的input完成历史使命后就消失了……(话说用户需要重新刷新才可以做下一波操作)

看了下mtag_tool的曲库路径实现,感觉如果input数量多一些后,这种input后马上output会很累。

如果 inputs 支持布局+非阻塞+提供value获取接口,库应该会更灵活。

Formatting table contents with variable table size

Hello! I'm really enjoying using this to convert some of my command-line tools to web-apps. While it is nice to make it so users don't have to go to the command-line, it would also be nice to give them a little bit more functionality.

One of my web-apps creates a table from a list of lists, that is formatted like such:

tasksList = [ [2012, hello, https://appurl], [2013, world, https://appurl] ]

The size of this list varies by a user based on the time range they would like to see data for. This isn't a problem if I'm just trying to output the list via put_table(tasksList, headers = ['Date','Title','URL']). The feature that I haven't been able to find is one that will allow the 'URL' column to be displayed as a URL, rather than text.

As an example if I just ran put_table(tasksList, headers = ['Date', 'Title', 'URL'] I would get something like:

|  Date  |  Title  |         URL   |
-------------------------------------
| 2012  |  hello  | https://appurl | 

where the URL column contains URLs but they are just text. I've tried using put_link within the put_table but I haven't figured out how to use it when the size of the table is variable.

Again, enjoying the library. Thank you.

[Feature request] 让输入组中 actions 的按钮支持自定义颜色

像 put_buttoms() 一样可以给按钮指定颜色

put_buttons([
    dict(label=i, value=i, color=i)  
    for i in ['primary' , 'secondary' , 'success' , 'danger' , 'warning' , 'info' , 'light' , 'dark']  
], onclick=put_text)

现在的情况

from pywebio import *
from pywebio.input import *

if __name__ == '__main__':
    input_group('Edit',[
        input('Shortname', type=TEXT, name='name', required=True),
        input('Url', type=URL, name='url', required=True),
        actions(buttons=[
            dict(label='Add', value='add', type='submit', color='primary'),
            dict(label='Reset', value='reset', type='reset', color='info'),
            dict(label='Cancel', value='calcel', type='cancel', color='secondary')
        ],name='action')
    ])


可见全都默认为 primary

  • PyWebIO版本: 1.2.3

聊天室demo启动错误

注: 对于PyWebIO使用咨询或对于其他人也可能有帮助的问题,请考虑移至 Discussions 进行发帖。

BUG描述
描述BUG表现以及复现方式。
如果浏览器控制台有报错以及脚本抛出异常也请将报错信息附上

from pywebio.session import defer_call, info as session_info, run_async

引用报错,无法加载;没有找到类似的函数

环境信息

  • 操作系统及版本:
  • 浏览器及版本:
  • Python版本: 使用 python3 --version 查看
  • PyWebIO版本: 使用 python3 -c "import pywebio;print(pywebio.__version__)" 查看

File upload progress bar not precise

Note: For inquiries while using PyWebIO or questions that might be helpful to others, please consider moving to Discussions for posting.

BUG Description
Seems not a big deal but still wanna raise it here.

I'm trying to upload a ~200MB file through the file_upload method, while the websocket_max_message_size has already been increased.

The progress bar goes into 100% in seconds but the upload actually finishes in about 2~3 minutes (measured by the trigger of the validate function), which may confuse the user.

I think the issue may be caused by the calculation method that only considers the file uploading procedure while misses the post-processing.
https://github.com/wang0618/PyWebIO/blob/49761f7084d5edc278414631785be7046d3ac690/webiojs/src/session.ts#L235-L238

Environment Information

  • OS and Version: Ubuntu 18.04
  • Browser and Version: Edge 88.0.705.29
  • Python Version: Python3.6.9
  • PyWebIO Version: 1.1.0

性能怎么样

看起来非常酷,用于生产环境的话,性能怎么样,看文档支持协程,高并发场景下应该能hold住吧

作为服务器部署的模式如何优雅地停止服务

注: 对于PyWebIO使用咨询或对于其他人也可能有帮助的问题,请考虑移至 Discussions 进行发帖。

BUG描述
描述BUG表现以及复现方式。
如果浏览器控制台有报错以及脚本抛出异常也请将报错信息附上

环境信息

  • 操作系统及版本:
  • 浏览器及版本:
  • Python版本: 使用 python3 --version 查看
  • $>: Python 3.7.9
  • PyWebIO版本: 使用 python3 -c "import pywebio;print(pywebio.__version__)" 查看
  • $>: 1.2.3

使用了start_server() 启动的服务,除了使用ctrl+c以外,有没有其他优雅的方式关闭服务。

[feature request] Share variables between inputs in input_group

Is it possible to define one of the inputs based on another input when we have multiple inputs in input_group? This requires some way of passing the output of an input in the input_group to the next input. An application of this is when we have two drop down menus for example and the options of the second drop down menu change based on what the user chooses from the first drop down menu. Something like this example:

DBs = ['DB1', 'DB2', 'DB3']
Tables = ['Table1', 'Table2', 'Table3', 'Table4']
text_info = input_group('Database and table name', [
                      select(label='Select the database of the table:', options=DBs, name='DB_name'),
                      select(label='Select the name of the table:', options=Tables, name='Table_name')
                      ])

So is there a way to bind the options of the second drop down menu above to the user selection from the first drop down? Like if the user chooses 'DB1' then the options in the second menu will be 'Table1' and 'Table2' but if the user chooses 'DB2' the options will be 'Table3' and 'Table4'.

实现类似文件夹折叠的功能

v友好。

我想实现一下类似于网盘列表类的前端功能,但是不知道有多少级,想每点击一次可以获取一下内容,类似于异步获取,不是一次性获取,而且每一级之前肯定要传递参数。我尝试回调但是无法写出循环额,回调没有返回值,也无法被下一次回调。尝试用put_link,但是也不行,貌似put_link无法传参。

put_buttons的点击事件不生效?

代码如下,本来写了一个自己的按钮,不生效,于是去demo拷贝了一下,还是不行

from pywebio import start_server
import pywebio.input as webinput
import pywebio.output as weboutput
from pywebio.session import set_env


def onClickCallback(val):
    weboutput.popup(title=val, content=val)


def main():
    set_env(title='put_buttons测试')

    weboutput.put_buttons([
        dict(label=i, value=i, color=i)
        for i in ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark']
    ], onclick=weboutput.put_text)


if __name__ == '__main__':
    start_server(main,debug=True,port=8060)

Windows下start_server报编码错误

注: 对于PyWebIO使用咨询或对于其他人也可能有帮助的问题,请考虑移至 Discussions 进行发帖。

BUG描述
描述BUG表现以及复现方式。
如果浏览器控制台有报错以及脚本抛出异常也请将报错信息附上
$ python file.py
Traceback (most recent call last):
File "C:\Users\zjan\Desktop\file.py", line 7, in
from pywebio import start_server
File "C:\Users\zjan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywebio_init_.py", line 3, in
from . import platform
File "C:\Users\zjan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywebio\platform_init_.py", line 93, in
from .httpbased import run_event_loop
File "C:\Users\zjan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywebio\platform\httpbased.py", line 17, in
from .utils import make_applications, render_page
File "C:\Users\zjan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywebio\platform\utils.py", line 19, in
_index_page_tpl = template.Template(open(path.join(_here_dir, 'tpl', 'index.html')).read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0xb9 in position 3806: illegal multibyte sequence

环境信息

  • 操作系统及版本: win10
  • 浏览器及版本: edge dev
  • Python版本:3.9
  • PyWebIO版本: 使用 python3 -c "import pywebio;print(pywebio.__version__)" 查看

[feature request] Output method to display video in browser

I am making a computer vision app where I need to display the webcam stream on the browser. Is there a way to do this currently in pywebio?

For example, in flask, we can do it this way. But, of course, since quite a lot of effort is needed to achieve this functionality in flask, I would very much love it if pywebio can handle this. Something like 'put_video', similar to 'put_image' would be great!

MacOS Firefox 84.0.2(64-bit)打开所有 demo 页面内容都是空白

BUG描述
前提:通过浏览器打开任意 Demo 页面。
现象:页面只能看到页脚,内容显示是空白。
其他信息:Chrome 和 Safari 都正常。

image

环境信息

  • 操作系统: MacOS
  • 浏览器及版本: Firefox 84.0.2(64-bit)
  • Python版本: 使用 python3 --version 查看
  • PyWebIO版本: 使用 python3 -c "import pywebio;print(pywebio.__version__)" 查看

WebSocket hanlder not working on my custom domain on Heroku

Background
Hey Wang, I'm currently hosting my app built using PyWebIO on Heroku, I have been trying to figure out why using
from pywebio.platform.tornado import webio_handler (instead of from pywebio.platform.tornado_http import webio_handler) doesn't work on my subdomain.

For example:
Using webio_handler from pywebio.platform.tornado. When I browse my app on https://example.herokuapp.com/, the app functions normally, ws connection was established, everything was working

WS network tab on my heroku domain
no_error

However, when I browse my app on my custom domain example.com (or with other subdomain), the page just doesn't load

Console & WS network tab on my custom domain:

WebSocket connection to 'wss://example.com
value | @ | pywebio.min.js:1
-- | -- | --
  | h | @ | pywebio.min.js:1
  | startWebIOClient | @ | pywebio.min.js:1
  | (anonymous) | @ | (index):72

/?app=index&session=NEW' failed: 

error

I've been trying to figure out this for the past 3 days, reading the entire docs as well as browsing through tornado's doc and I can't seem to find an answer.
I currently resolve to using webio_handler from pywebio.platform.tornado_http instead, however I am curious to know more

[feature request] auto-load app when running the app, and auto-refresh when changing the code

I have built a webapp which runs like so:

pywebio.start_server(app, port=8080, debug=True)

But when I run the code, it does not automatically open the app in the browser; I need to manually type the address in the browser and run it.

Also, when I change my code while the app is running, it does not auto-refresh the webpage, and I need to refresh it manually.

Is there a way to do these already? If not, it would be a nice thing to add.

multiple routes

Hello again,
what is the best and easiest way to have multiple routes app?
Tried to use flask with app.add_url_rule() but for multiple routes got the error

webio_view() can not be over write.

Thanks

server stuck and failed to start when trying to load image from the very beginning

BUG描述
The server got stuck when I trying to create an output before start_server

The original purpose is to make pywebio display an image, and once a button gets clicked the image will change into another. But I found if I declare the output before the start server callback function, the program will be stuck.

The bad code:

import ...

image = open('image/url/')
image_output = put_image(image)

def main():
    put_table([image_output])

if __main__ == '__main__':
    start_server(main,port=9090)

after python3 server.py it shows nothing as the program got stuck.

The error message when I ctrl^C is
image

seems it's trying to acquire a lock.

and it can be fixed if I declare the image_output inside the main loop as follows

import ...

def main():
    image = open('image/url/')
    image_output = put_image(image)
    put_table([image_output])

if __main__ == '__main__':
    start_server(main,port=9090)

环境信息

  • 操作系统: Ubuntu 18.04.1 LTS
  • 浏览器及版本: N/A
  • Python版本: 使用 python3 --version 查看 python3.6.9
  • PyWebIO版本: 使用 python3 -c "import pywebio;print(pywebio.__version__)" 查看 1.1.0.dev2102240823

With this bug, I'm wondering how could I implement my original design?
I decided to declare theimage_output as a global variable, which the button callback will update after a click.

image_output = put_image(original_image)

def callback:
    image_output.reset(put_image(new_image))

def main:
    put_table([put_buttons(['button'], onclick=callback), image_output])

if __main__ == '__main__':
    start_server(main,port=9000)

Is there any alternative approaching?

Heroku

How to deploy app to heroku?

Slider support?

Requesting a feature add - slider.

For multi-parameter apps, a slider is a natural choice for many situations. Especially, it gives an idea about the range of values to experiment with.

Add javascript tag

Hello,
How it is possible to add Javascript tag to PyWebio? E.g. Google analytics or other analytics tools.
Thanks.

[Feature Request] start_scriptmode server function

Hey, pywebio is an awesome idea, thank you for that :)

Thanks to corona im regularly working remotely over ssh, and when I want to toy around with data, I usually generate html files that contain plots and tables, copy them to my local machine, and open them here (sshfs has some quirks inside wsl2). I had hoped to be able to use pywebio instead, but when run in scripting mode, the server is always opened on another port. I thought, maybe I could just look at the port, in which it opens using the session.info, and then create a local port forwarding (so there would be two forwardings: my machine:8080 -> server:8080 and server:8080 -> wherever pywebio runs), im not sure, whether that would have worked, but I couldn't try, because pywebio would always open a browser on the server (lynx or w3m since no X), and then it would freeze on the first put_ function, probably because they rely on some feature the browser doesn't support. After uninstalling lynx and w3m, nothing changed.
So what would be awesome for me, would be a function start_script_mode_server(port=8080, openBrowser=False) I first tried to add it myself, but the code base is too complex to understand it quickly (and web is not really my forte), and I can't read Chinese, which a lot of comments are in. If you would be willing to add this feature, that would be awesome.

PS: sorry, I dont know how to remove the bug label

Jupyter Notebook Data Visualization Returns Blank

BUG Description

Running the following code to create Plotly Data Visualization inside Jupyter Notebook returns a blank page:

from pywebio.output import put_html
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)

import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
                   dtype={"fips": str})

import plotly.express as px

fig = px.choropleth_mapbox(df, geojson=counties, locations='fips', color='unemp',
                           color_continuous_scale="Viridis",
                           range_color=(0, 12),
                           mapbox_style="carto-positron",
                           zoom=3, center = {"lat": 37.0902, "lon": -95.7129},
                           opacity=0.5,
                           labels={'unemp':'unemployment rate'}
                          )
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
html = fig.to_html(include_plotlyjs="require", full_html=False)
put_html(html)`

Environment Information

  • OS and Version: Windows 10
  • Browser and Version: Chrome
  • Python Version: Use python3 --version to view : 3.8
  • PyWebIO Version: Use python3 -c "import pywebio;print(pywebio.__version__)" to view: 1.2.3

TypeError: object NoneType can't be used in 'await' expression

功能正常运行就是报个错误

In [2]: import pywebio

In [3]: pywebio.version
Out[3]: '1.2.3'

python3.8 chat_room.py
Listen on 0.0.0.0:8080
ERROR:tornado.application:Uncaught exception GET /?app=index&session=NEW (::1)
HTTPServerRequest(protocol='http', host='localhost:8080', method='GET', uri='/?app=index&session=NEW', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "/home/arthur/.local/lib/python3.8/site-packages/tornado/web.py", line 1592, in _execute
result = yield result
File "/home/arthur/.local/lib/python3.8/site-packages/tornado/gen.py", line 1133, in run
value = future.result()
File "/home/arthur/.local/lib/python3.8/site-packages/pywebio/platform/tornado.py", line 106, in get
await super().get()
TypeError: object NoneType can't be used in 'await' expression

put_image 格式问题

BUG描述
put_img 函数中 当图像来源是 PILImage 时, 其format 可能会是 None
比如 该实例是由 Image.frombytes 生成

环境信息

  • Win10
  • Chrome 89.0.4389.128
  • 3.7.9
  • 1.2.3

[Feature request] 输入域 (Input Scope)

目前Scope概念仅存在于output模块中,烦请考虑将Scope支持带到输入模块中

这将带来:

  1. 输入框也可以参与grid内容布局
  2. 可以主动移除仍在等待输入的input/input group
  3. etc

Matplotlib support for `put_image`?

Can you integrate Matplotlib support for put_image() function i.e. somehow it can accept a Matplotlib figure object and render it nicely? This will open up a range of data science applications.

I know you have Bokeh and Plotly integration but a lot of users are more comfortable with Matplotlib than Bokeh or Plotly.

Output相关控件的 update 建议

这个库很好,很适合后端用。

这里提点建议:

目前,pywebio.output里面的progressbar很不错。在输出后,可以多次更新。(有set方法)

但是,其他的控件在输出后,就失去再次更新的能力了。

能否给每个output空间都加入name,后续可以依据name再次更新其内容?(就像progressbar一样)

BTW:文档里面“输出域”这个章节,貌似重复出现在input和output里面了,直觉上看,应该只是output的功能。不知道是不是我读的不细,抽空检查下是不是出错了。

[feature request] input_group() to support more input functions

input_group() in the current version seems only support input() and actions(). To construct more user-friendly forms, the proposal is asking input_group() to also support all other functions. A use case:

input_group("title", [
  input('label', name='name1'),
  radio('label', ['option1', 'option2']),
  file_upload('lable')
   ])

How can I override the <head> tag for my page?

Hi, may I know is there a way I can add some more <script> tags inside the <head> section of the default HTML>?

<!doctype html>
  | <html lang="">
  | <head>
  | <meta charset="UTF-8">
  | <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  | <title>Example</title>
  | <meta name="description" content="Foo bar">
  | <link rel="icon" type="image/png" sizes="32x32" 
 ...
  | <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/wang0618/[email protected]/css/toastify.min.css">
  | <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/wang0618/[email protected]/css/app.css">
  | </head>
 
<body>
  | <div class="pywebio">

Eval_js in non-coroutine inside run_async doesn't work

BUG Description

Running lol = run_async(eval_js("console.log('Hello'))) in a non-coroutine session doesn't work and it freezes and doesn't go on, so it executes nothing after it. No error, No nothing. The same also happens without run_async. run_js works.

Environment Information

  • OS and Version: Manjaro, newest
  • Browser and Version: Brave/Firefox Dev edition
  • Python Version: 3.9.4
  • PyWebIO Version: 1.2.3.dev2105160323

Option for disabling the separate frames for long pages

For long pages, you are creating a separate frame for the input section i.e. the upper section of the page (introduction markdown, etc.) goes into a different section. This is the current default behavior.

Can you please keep an option to enable or disable this i.e. a long page just scrolls normally and does not scroll in different frames.

python 3.6.13 &.7.1

注: 对于PyWebIO使用咨询或对于其他人也可能有帮助的问题,请考虑移至 Discussions 进行发帖。

BUG描述
描述BUG表现以及复现方式。
如果浏览器控制台有报错以及脚本抛出异常也请将报错信息附上

环境信息

  • 操作系统及版本:
  • 浏览器及版本:
  • Python版本: 使用 python3 --version 查看
  • PyWebIO版本: 使用 python3 -c "import pywebio;print(pywebio.__version__)" 查看

put_markdown 输出图片路径如何填写

V友您好,

请教一下:
假定程序根路径有一个me.jpg 图片。

如下三句, 后两句可以正常显示,第一句用put_markdown不行。
请教put_markdown 图片地址如何填写。

    put_markdown("![test](me.jpg)")
    img = open('me.jpg', 'rb').read()  
    put_image(img, width='50px')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.