deephaven / deephaven-plugins

Deephaven Plugins
11 stars 15 forks source link

Ability to use `ui.image`, `ui.avatar` with local images #1040

Open mofojed opened 3 days ago

mofojed commented 3 days ago

Currently you can only serve up an image that is publicly accessible, e.g. i = ui.image("https://github.com/deephaven.png"). If you try and serve up a local image to the container, you'll just get an error because the path will not be local to the client. We should be able to use a local image. E.g. you should be able to specify: i = ui.image('./plugins/ui/docs/_assets/text_filter_table.png') and it should just magically work.

Note there is a workaround currently by base64 encoding the image:

import base64
from deephaven import ui

with open("./plugins/ui/docs/_assets/text_filter_table.png", 'rb') as f:
    file_content = f.read()

b64_image = ui.image(f"data:image/png;base64,{base64.b64encode(file_content).decode()}")
dsmmcken commented 3 days ago

I would try to generalize this as much as possible.

Like imagine someone doing .write_csv("./path/to/file") and the using a ui.link("Download file", href="./path/to/file", download=True)