.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/cube_http.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_cube_http.py: Cube in the browser ------------------- Run a wgpu example with the http backend. Note that the http backend can be used with most examples by simply using ``from rendercanvas.http import RenderCanvas, loop``. This example also shows how the web-page can be customized. Also see fastapi_app.py for how to integrate a rendercanvas into a larger web application. .. GENERATED FROM PYTHON SOURCE LINES 12-61 .. code-block:: Python # run_example = false from rendercanvas.http import RenderCanvas, loop, resources from rendercanvas.utils.cube import setup_drawing_sync from rendercanvas.core.encoders import encode_png import numpy as np canvas = RenderCanvas( title="The wgpu cube example on $backend", update_mode="continuous" ) draw_frame = setup_drawing_sync(canvas) canvas.request_draw(draw_frame) # Define custom HTML. This is optional. html = """ RenderCanvas over http
Loading ...
""" # The resources is simply a dict that maps filenames to (content-type, body) tuples. resources["index.html"] = "text/html", html # You can also add new resources, like images or even extra web pages. im = np.random.uniform(0, 255, (16, 16, 3)).astype(np.uint8) resources["logo.png"] = "image/png", encode_png(im) # The loop.run() of this backend uses uvicorn to start a webserver. # The args are optional and default to "localhost" and port 60649 loop.run("localhost", 8080) .. _sphx_glr_download_gallery_cube_http.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cube_http.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cube_http.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: cube_http.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_