-
Notifications
You must be signed in to change notification settings - Fork 16
feat: Add ui.resolve to support URIs in dh.ui #1215
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
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
57d4ca7
Basic support for ui.resolve
mattrunyon daa7f03
Adjust isObjectView checks
mattrunyon b8b6931
Fetch deferred api for UriObjectView
mattrunyon cebf312
Make ui.resolve work as a top level widget
mattrunyon 6db5dd2
Fix UITable loading the wrong dh instance
mattrunyon ffffec6
Handle PQ reloads
mattrunyon a91fd15
Adjust import
mattrunyon fce3136
Update to alpha packages
mattrunyon cab41be
Update packages
mattrunyon 9b5fdb9
Address review comments
mattrunyon 2572afa
Merge branch 'main' into dh-19001
mattrunyon 7b73bda
Fix most test errors
mattrunyon 9f816fa
Add docs
mattrunyon 67c90fe
Address review comments
mattrunyon 5499230
Update packages
mattrunyon 26be31b
Fix types and e2e error
mattrunyon 6efa116
Add error state for listview/picker/combobox
mattrunyon 3359aff
Update to 1.5.1 for listview error icon
mattrunyon cb01562
Merge remote-tracking branch 'upstream/main' into dh-19001
mattrunyon 86538ed
Fix props type
mattrunyon 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,74 @@ | ||
| # URI | ||
|
|
||
| URIs are a way to reference Deephaven resources, such as tables or figures, from another instance. Deephaven UI has its own `ui.resolve` method that does not require server-to-server communication. Instead, the web client communicates directly with the appropriate server to get the resource. | ||
|
|
||
| ## Usage | ||
|
|
||
| Deephaven UI provides a `resolve` method (not to be confused with the `resolve` method from the [Deephaven URI package](/core/pydoc/code/deephaven.uri.html)) that allows you to reference Deephaven resources from other instances. Unlike the Deephaven URI package, `ui.resolve` does not resolve the URI to its resource on the server, so you cannot apply operations to the resource. | ||
|
|
||
| > [!NOTE] | ||
| > Currently, the only valid URIs for Deephaven UI are for Deephaven Enterprise Persistent Queries. | ||
| > See the [Deephaven Enterprise documentation](/enterprise/docs/deephaven-database/remote-tables-python/#uris) for more information on Persistent Query URIs. The optional parameters are ignored by `ui.resolve`. | ||
|
|
||
| ### Plain references | ||
|
|
||
| One way to use `ui.resolve` is to assign the reference to a variable, which the web UI will open just as if you created the resource. This can be useful if you want to display tables from multiple sources in a single dashboard without the worker defining the dashboard pulling the data from each source. | ||
|
|
||
| ```py order=null | ||
| from deephaven import ui | ||
|
|
||
| t = ui.resolve("pq://MyPersistentQuery/scope/table") # Can't do t.update() or any other operations | ||
| p = ui.resolve("pq://MyPersistentQuery/scope/plot") | ||
|
|
||
|
|
||
| @ui.component | ||
| def basic_dashboard(): | ||
| return ui.panel(ui.flex(t, p), title="Table and Plot") | ||
|
|
||
|
|
||
| my_dashboard = ui.dashboard(basic_dashboard()) | ||
| ``` | ||
|
|
||
| ### Usage in UI components | ||
|
|
||
| Some Deephaven UI components that accept tables as sources can also accept URIs. This includes [`ui.table`](table.md) and any components that accept an `item_table_source`. When using a URI with UI components, you can often just use the string without needing to call `ui.resolve`. However, if a component may take a string as a valid child (e.g., `ui.picker`), then you must use `ui.resolve` to distinguish between a string and a URI. You can always use `ui.resolve` in places where you can use just the string if you prefer to be explicit. | ||
|
|
||
| > [!WARNING] | ||
| > Deephaven UI URIs cannot be used as table sources in the Deephaven Express plotting library. | ||
|
|
||
| ```py order=null | ||
| from deephaven import ui | ||
|
|
||
| # You can use any ui.table props with a URI source | ||
| t = ui.table( | ||
| "pq://MyPersistentQuery/scope/table", | ||
| format_=ui.TableFormat(cols="A", background_color="salmon") | ||
| ) | ||
|
|
||
| # Must use ui.resolve because string is a valid child | ||
| picker = ui.picker( | ||
| ui.resolve("pq://MyPersistentQuery/scope/picker_table"), | ||
| label="Picker Table" | ||
| ) | ||
|
|
||
| list_view = ui.list_view( | ||
| ui.item_table_source( | ||
| "pq://MyPersistentQuery/scope/list_view_table", | ||
| key_column="Keys", | ||
| label_column="Labels" | ||
| ) | ||
| ) | ||
| ``` | ||
|
|
||
| ## URI Encoding | ||
|
|
||
| If your URI contains any special characters, such as spaces or slashes, you must encode the URI components using standard URL encoding. This is because URIs are often used in web contexts where special characters can cause issues. You can use Python's built-in `urllib.parse.quote` function to encode your URIs. | ||
|
|
||
| ```py order=null | ||
| from urllib.parse import quote | ||
| from deephaven import ui | ||
|
|
||
| # Encode the URI | ||
| pq_name = quote("My PQ/with spaces!", safe="") # safe="" will encode the forward slash | ||
mattrunyon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| t = ui.resolve(f"pq://{pq_name}/scope/table") | ||
| ``` | ||
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.
Mixed feelings here... should we be explaining this on the Core side? Or on the Enterprise side? We really should have a utility method that accepts the query name and object name to make the URI for you, with proper encoding,
ui.query_resolveor something, e.g.ui.query_resolve(query="MyQueryName", widget="MyWidget"). Technically it'd be Core+ only, but I wouldn't feel terrible about putting it in Core anyways...As for this part - "If your URI contains any special characters" - moreso should be "You can construct a URI with any query name. If your query name contains special characters, such as spaces or slashes, you must encode the name first to avoid mangling the URL". (But nicer)