libraries_support.rst 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. Libraries support
  2. ======================
  3. .. _stand_alone_app:
  4. Build stand-alone App
  5. ----------------------
  6. `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.
  7. You can use PyInstaller to packages PyWebIO application into a stand-alone executable or folder:
  8. 1. Create a pyinstaller spec (specification) file::
  9. pyi-makespec <options> app.py
  10. You need replace ``app.py`` to your PyWebIO application file name.
  11. 2. Only for PyWebIO before v1.8: Edit the spec file, change the ``datas`` parameter of ``Analysis``::
  12. from pywebio.utils import pyinstaller_datas
  13. a = Analysis(
  14. ...
  15. datas=pyinstaller_datas(),
  16. ...
  17. 3. Build the application by passing the spec file to the pyinstaller command::
  18. pyinstaller app.spec
  19. If you want to create a one-file bundled executable, you need pass ``--onefile`` option in first step.
  20. For more information, please visit: https://pyinstaller.readthedocs.io/en/stable/spec-files.html
  21. .. _visualization:
  22. Data visualization
  23. --------------------
  24. PyWebIO supports for data visualization with the third-party libraries.
  25. Bokeh
  26. ^^^^^^^^^^^^^^^^^^^^^^
  27. `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.
  28. You can use ``bokeh.io.output_notebook(notebook_type='pywebio')`` in the PyWebIO session to setup Bokeh environment.
  29. Then you can use ``bokeh.io.show()`` to output a boken chart::
  30. from bokeh.io import output_notebook
  31. from bokeh.io import show
  32. output_notebook(notebook_type='pywebio')
  33. fig = figure(...)
  34. ...
  35. show(fig)
  36. See related demo on :charts_demo_host:`bokeh demo </?app=bokeh>`
  37. 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.
  38. 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>`_.
  39. .. note:: Bokeh App currently is only available in the default Tornado backend
  40. .. image:: https://fastly.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/bokeh.png
  41. pyecharts
  42. ^^^^^^^^^^^^^^^^^^^^^^
  43. `pyecharts <https://github.com/pyecharts/pyecharts>`_ is a python plotting library which uses `Echarts <https://github.com/ecomfe/echarts>`_ as underlying implementation.
  44. In PyWebIO, you can use the following code to output the pyecharts chart instance::
  45. # `chart` is pyecharts chart instance
  46. pywebio.output.put_html(chart.render_notebook())
  47. See related demo on :charts_demo_host:`pyecharts demo </?app=pyecharts>`
  48. .. only:: not latex
  49. .. image:: https://fastly.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/pyecharts.gif
  50. plotly
  51. ^^^^^^^^^^^^^^^^^^^^^^
  52. `plotly.py <https://github.com/plotly/plotly.py>`_ is an interactive, open-source, and browser-based graphing library for Python.
  53. In PyWebIO, you can use the following code to output the plotly chart instance::
  54. # `fig` is plotly chart instance
  55. html = fig.to_html(include_plotlyjs="require", full_html=False)
  56. pywebio.output.put_html(html)
  57. See related demo on :charts_demo_host:`plotly demo </?app=plotly>`
  58. .. image:: https://fastly.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/plotly.png
  59. pyg2plot
  60. ^^^^^^^^^^^^^^^^^^^^^^
  61. `pyg2plot <https://github.com/hustcc/PyG2Plot>`_ is a python plotting library which uses `G2Plot <https://github.com/antvis/G2Plot>`_ as underlying implementation.
  62. In PyWebIO, you can use the following code to output the pyg2plot chart instance::
  63. # `chart` is pyg2plot chart instance
  64. pywebio.output.put_html(chart.render_notebook())
  65. See related demo on :charts_demo_host:`plotly demo </?app=pyg2plot>`
  66. cutecharts.py
  67. ^^^^^^^^^^^^^^^^^^^^^^
  68. `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.
  69. In PyWebIO, you can use the following code to output the cutecharts.py chart instance::
  70. # `chart` is cutecharts chart instance
  71. pywebio.output.put_html(chart.render_notebook())
  72. See related demo on :charts_demo_host:`cutecharts demo </?app=cutecharts>`
  73. .. image:: https://fastly.jsdelivr.net/gh/wang0618/pywebio-chart-gallery@master/assets/cutecharts.png