libraries_support.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. Libraries support
  2. ======================
  3. Build stand-alone App
  4. ----------------------
  5. `PyInstaller <https://pyinstaller.readthedocs.io/en/stable/>`_ bundles a Python application and all its dependencies into a folder or executable. The user can run the packaged app without installing a Python interpreter or any modules.
  6. You can use PyInstaller to packages PyWebIO application into a stand-alone executable or folder:
  7. 1. Create a pyinstaller spec (specification) file::
  8. pyi-makespec <options> app.py
  9. You need replace ``app.py`` to your PyWebIO application file name.
  10. 2. Edit the spec file, change the ``datas`` parameter of ``Analysis``::
  11. from pywebio.util import pyinstaller_datas
  12. a = Analysis(
  13. ...
  14. datas=pyinstaller_datas(),
  15. ...
  16. 3. Build the application by passing the spec file to the pyinstaller command::
  17. pyinstaller app.spec
  18. If you want to create a one-file bundled executable, you need pass ``--onefile`` option in first step.
  19. For more information, please visit: https://pyinstaller.readthedocs.io/en/stable/spec-files.html
  20. .. _visualization:
  21. Data visualization
  22. --------------------
  23. PyWebIO supports for data visualization with the third-party libraries.
  24. Bokeh
  25. ^^^^^^^^^^^^^^^^^^^^^^
  26. `Bokeh <https://github.com/bokeh/bokeh>`_ is an interactive visualization library for modern web browsers. It provides elegant, concise construction of versatile graphics, and affords high-performance interactivity over large or streaming datasets.
  27. You can use ``bokeh.io.output_notebook(notebook_type='pywebio')`` in the PyWebIO session to setup Bokeh environment.
  28. Then you can use ``bokeh.io.show()`` to output a boken chart::
  29. from bokeh.io import output_notebook
  30. from bokeh.io import show
  31. output_notebook(notebook_type='pywebio')
  32. fig = figure(...)
  33. ...
  34. show(fig)
  35. See related demo on :charts_demo_host:`bokeh demo </?app=bokeh>`
  36. In addition to creating ordinary charts, Bokeh can also build the Bokeh applications by starting the `Bokeh server <https://docs.bokeh.org/en/latest/docs/user_guide/server.html>`_. The purpose of the Bokeh server is to make it easy for Python users to create interactive web applications that can connect front-end UI events to real, running Python code.
  37. In PyWebIO, you can also use ``bokeh.io.show()`` to display a Bokeh App. For the example, see `bokeh_app.py <https://github.com/wang0618/PyWebIO/blob/dev/demos/bokeh_app.py>`_.
  38. .. note:: Bokeh App currently is only available in the default Tornado backend
  39. .. image:: https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/bokeh.png
  40. pyecharts
  41. ^^^^^^^^^^^^^^^^^^^^^^
  42. `pyecharts <https://github.com/pyecharts/pyecharts>`_ is a python plotting library which uses `Echarts <https://github.com/ecomfe/echarts>`_ as underlying implementation.
  43. In PyWebIO, you can use the following code to output the pyecharts chart instance::
  44. # `chart` is pyecharts chart instance
  45. pywebio.output.put_html(chart.render_notebook())
  46. See related demo on :charts_demo_host:`pyecharts demo </?app=pyecharts>`
  47. .. only:: not latex
  48. .. image:: https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/pyecharts.gif
  49. plotly
  50. ^^^^^^^^^^^^^^^^^^^^^^
  51. `plotly.py <https://github.com/plotly/plotly.py>`_ is an interactive, open-source, and browser-based graphing library for Python.
  52. In PyWebIO, you can use the following code to output the plotly chart instance::
  53. # `fig` is plotly chart instance
  54. html = fig.to_html(include_plotlyjs="require", full_html=False)
  55. pywebio.output.put_html(html)
  56. See related demo on :charts_demo_host:`plotly demo </?app=plotly>`
  57. .. image:: https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/plotly.png
  58. pyg2plot
  59. ^^^^^^^^^^^^^^^^^^^^^^
  60. `pyg2plot <https://github.com/hustcc/PyG2Plot>`_ is a python plotting library which uses `G2Plot <https://github.com/antvis/G2Plot>`_ as underlying implementation.
  61. In PyWebIO, you can use the following code to output the pyg2plot chart instance::
  62. # `chart` is pyg2plot chart instance
  63. pywebio.output.put_html(chart.render_notebook())
  64. See related demo on :charts_demo_host:`plotly demo </?app=pyg2plot>`
  65. cutecharts.py
  66. ^^^^^^^^^^^^^^^^^^^^^^
  67. `cutecharts.py <https://github.com/cutecharts/cutecharts.py>`_ is a hand drawing style charts library for Python which uses `chart.xkcd <https://github.com/timqian/chart.xkcd>`_ as underlying implementation.
  68. In PyWebIO, you can use the following code to output the cutecharts.py chart instance::
  69. # `chart` is cutecharts chart instance
  70. pywebio.output.put_html(chart.render_notebook())
  71. See related demo on :charts_demo_host:`cutecharts demo </?app=cutecharts>`
  72. .. image:: https://cdn.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/cutecharts.png