render.image

render.image(self, _fn=None, *, delete_file=False)

Reactively render a image file as an HTML image.

Parameters

delete_file: bool = False

If True, the image file will be deleted after rendering.

Returns

Type Description
A decorator for a function that returns an ImgData object.

Tip

The name of the decorated function (or @output(id=...)) should match the id of a output_image container (see output_image for example usage).

See Also

Examples

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400

## file: app.py
from shiny import App, Inputs, Outputs, Session, render, ui
from shiny.types import ImgData

app_ui = ui.page_fluid(ui.output_image("image"))


def server(input: Inputs, output: Outputs, session: Session):
    @render.image
    def image():
        from pathlib import Path

        dir = Path(__file__).resolve().parent
        img: ImgData = {"src": str(dir / "posit-logo.png"), "width": "100px"}
        return img


app = App(app_ui, server)