-
Notifications
You must be signed in to change notification settings - Fork 16
fix: DH-18073: ui.image convert bytes to str (#1167) #1199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mofojed
merged 2 commits into
deephaven:release/ui-v0.29
from
mofojed:DH-18703-fix-ui.image
Jun 27, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # Static Image Export | ||
|
|
||
| Convert a `DeephavenFigure` to a static image using the `to_image_uri` method. | ||
| In order to use this feature, you need to have the `kaleido` package installed. | ||
| Either install will `all` extras or install `kaleido` separately. | ||
|
|
||
| ```sh | ||
| pip install 'deephaven-plugin-plotly-express[all]' | ||
| ``` | ||
| or | ||
| ```sh | ||
| pip install kaleido | ||
| ``` | ||
|
|
||
| > [!WARNING] | ||
| > The image is generated on the server, so it does not have access to client-side information such as timezones or theme. | ||
| > The theme is customizable with the `template` argument, but the default is not the same as a client theme. | ||
|
|
||
| ## `to_image` | ||
|
|
||
| The `to_image` method allows you to export a `DeephavenFigure` to bytes, which can be embedded as an image. | ||
|
|
||
| ```python order=line_plot_image | ||
| import deephaven.plot.express as dx | ||
| from deephaven import ui | ||
|
|
||
| dog_prices = dx.data.stocks() | ||
|
|
||
| line_plot = dx.line(dog_prices, x="Timestamp", y="Price", by="Sym") | ||
|
|
||
| # Export the plot to bytes | ||
| line_plot_bytes = line_plot.to_image() | ||
|
|
||
| # Embed the image in a Deephaven UI image element | ||
| line_plot_image = ui.image(src=line_plot_bytes) | ||
| ``` | ||
|
|
||
| ## Theme Template | ||
|
|
||
| Customize the theme with the `template` argument. | ||
| Default options are `"plotly"`, `"plotly_white"`, `"plotly_dark"`, `"ggplot2"`, `"seaborn"`, and `"simple_white"`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be nice to do - "Default options are:
and so on |
||
|
|
||
| ```python order=line_plot_image | ||
| import deephaven.plot.express as dx | ||
| from deephaven import ui | ||
|
|
||
| dog_prices = dx.data.stocks() | ||
|
|
||
| line_plot = dx.line(dog_prices, x="Timestamp", y="Price", by="Sym") | ||
|
|
||
| # Use the template to change the theme | ||
| line_plot_bytes = line_plot.to_image(template="ggplot2") | ||
|
|
||
| # Embed the image in a Deephaven UI image element | ||
| line_plot_image = ui.image(src=line_plot_bytes) | ||
| ``` | ||
|
|
||
| ## Image Format | ||
|
|
||
| Customize the format with the `format` argument. | ||
| Options are `"png"`, `"jpg"`, `"jpeg"`, `"webp"`, `"svg"`, and `"pdf"`. | ||
|
|
||
| ```python order=line_plot_image | ||
| import deephaven.plot.express as dx | ||
| from deephaven import ui | ||
|
|
||
| dog_prices = dx.data.stocks() | ||
|
|
||
| line_plot = dx.line(dog_prices, x="Timestamp", y="Price", by="Sym") | ||
|
|
||
| # Use the format argument to change the image format | ||
| line_plot_bytes = line_plot.to_image(format="jpg") | ||
|
|
||
| # Embed the image in a Deephaven UI image element | ||
| line_plot_image = ui.image(src=line_plot_bytes) | ||
| ``` | ||
|
|
||
| ## Image Size | ||
|
|
||
| Customize the size with the `width` and `height` arguments. The values are in pixels. | ||
|
|
||
| ```python order=line_plot_image | ||
| import deephaven.plot.express as dx | ||
| from deephaven import ui | ||
|
|
||
| dog_prices = dx.data.stocks() | ||
|
|
||
| line_plot = dx.line(dog_prices, x="Timestamp", y="Price", by="Sym") | ||
|
|
||
| # Use the width and height arguments to change the size | ||
| line_plot_bytes = line_plot.to_image(width=800, height=600) | ||
|
|
||
| # Embed the image in a Deephaven UI image element | ||
| line_plot_image = ui.image(src=line_plot_bytes) | ||
| ``` | ||
|
|
||
| ## Write to a File | ||
|
|
||
| Export the image to bytes using the `to_image` method, then write the bytes to a file. | ||
|
|
||
| ```python skip-test | ||
| import deephaven.plot.express as dx | ||
|
|
||
| dog_prices = dx.data.stocks() | ||
|
|
||
| line_plot = dx.line(dog_prices, x="Timestamp", y="Price", by="Sym") | ||
|
|
||
| # Export the plot to bytes | ||
| line_plot_bytes = line_plot.to_image() | ||
|
|
||
| # Write the image to a file in the current directory | ||
| with open("line_plot.png", "wb") as f: | ||
| f.write(line_plot_bytes) | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.