-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(maidr.show): support py-shiny renderer #67
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4fdfcd1
fix: redesigning shiny and reusing existing render for iframe generation
krishnanand5 042eb70
fix: resolving lint errors
krishnanand5 209351e
fix: added render_maidr as the sole decorator and simplified shiny re…
krishnanand5 3f2693e
fix: incorporate pascalcase for RendrMaidr
krishnanand5 97bba1f
fix: downgrade poetry to 23.3.0 and delete .flake8
krishnanand5 a7f3d2e
fix: lint issue with histogram.py
krishnanand5 fb7f873
fix: revert classname to snake_case
krishnanand5 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 was deleted.
Oops, something went wrong.
This file contains 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,52 @@ | ||
import matplotlib.pyplot as plt | ||
import seaborn as sns | ||
from shiny import App, ui | ||
|
||
from maidr.widget.shiny import RenderMaidr | ||
|
||
# Load the dataset | ||
iris = sns.load_dataset("iris") | ||
|
||
# Define the UI components for the Shiny application | ||
app_ui = ui.page_fluid( | ||
ui.row( | ||
ui.column( | ||
3, | ||
ui.input_select( | ||
"x_var", | ||
"Select X variable:", | ||
choices=iris.select_dtypes(include=["float64"]).columns.tolist(), | ||
selected="sepal_length", | ||
), | ||
ui.input_select( | ||
"y_var", | ||
"Select Y variable:", | ||
choices=iris.select_dtypes(include=["float64"]).columns.tolist(), | ||
selected="sepal_width", | ||
), | ||
), | ||
ui.column(9, ui.output_ui("create_reactivebarplot")), | ||
) | ||
) | ||
|
||
|
||
# Define the server | ||
def server(input, output, session): | ||
@RenderMaidr | ||
def create_reactivebarplot(): | ||
fig, ax = plt.subplots(figsize=(10, 6)) | ||
s_plot = sns.scatterplot( | ||
data=iris, x=input.x_var(), y=input.y_var(), hue="species", ax=ax | ||
) | ||
ax.set_title(f"Iris {input.y_var()} vs {input.x_var()}") | ||
ax.set_xlabel(input.x_var().replace("_", " ").title()) | ||
ax.set_ylabel(input.y_var().replace("_", " ").title()) | ||
return s_plot | ||
|
||
|
||
# Create the app | ||
app = App(app_ui, server) | ||
|
||
# Run the app | ||
if __name__ == "__main__": | ||
app.run() |
This file contains 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 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 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 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,29 @@ | ||
from __future__ import annotations | ||
|
||
from shiny.render import ui | ||
from shiny.types import Jsonifiable | ||
|
||
import maidr | ||
|
||
|
||
class RenderMaidr(ui): | ||
""" | ||
A custom UI rendering class for Maidr objects in Shiny applications. | ||
|
||
This class extends the Shiny UI rendering functionality to handle Maidr objects. | ||
|
||
Methods | ||
------- | ||
render() | ||
Asynchronously renders the Maidr object. | ||
""" | ||
|
||
async def render(self) -> Jsonifiable: | ||
"""Return maidr rendered object for a given plot.""" | ||
initial_value = await self.fn() | ||
if initial_value is None: | ||
return None | ||
|
||
maidr_rendered = maidr.render(initial_value) | ||
transformed = await self.transform(maidr_rendered) | ||
return transformed |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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.
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.
@krishnanand5 shiny breaks the conventional Pascal case for classes, since this will be used as a decorator, like
@render_maidr
. There have followe this convention for all their renderers. So, we should also follow their convention.cc: @jooyoungseo
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.
Thank you for the confirmation @SaaiVenkat. I thought our repository's naming convention superseded supporting libraries but you are right. Better to follow the naming convention of the supporting libraries. I have reverted the class name to
snake_case