-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add interactive plots with Plotly #163
base: main
Are you sure you want to change the base?
Add interactive plots with Plotly #163
Conversation
Do you consider that a new test is needed for the module? |
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.
@javierbg Thanks for the pull request! The code looks solid but I haven't tested it yet. This seems like a great feature to include in the dashboard examples. Can you add an example there? Then I'll re-review and test the example on my machine.
doc/api.rst
Outdated
@@ -45,6 +45,7 @@ Dashboard Modules | |||
modules.StatepointList | |||
modules.TextDisplay | |||
modules.VideoViewer | |||
modules.PlotViewer |
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.
Alphabetize this in the list.
signac_dashboard/modules/__init__.py
Outdated
@@ -20,4 +21,5 @@ | |||
"StatepointList", | |||
"TextDisplay", | |||
"VideoViewer", | |||
"PlotViewer", |
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.
Alphabetize this in the list.
dashboard.app.route("/module/plot_viewer/<path:filename>")(plot_viewer_asset) | ||
|
||
# Register assets | ||
assets = ["js/plot_viewer.js", "js/plotly-2.16.1.min.js"] |
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.
This asset is pretty large and it seems like it changes often (could get outdated, at the relatively slow pace of signac-dashboard development). Can we use the CDN instead?
Note that you'll need to rewrite the git history on this branch to prevent the inclusion of this file in the git history. If you need help with this task or are uncertain about how to do it correctly, let me know and I'll take care of it!
assets = ["js/plot_viewer.js", "js/plotly-2.16.1.min.js"] | |
assets = ["js/plot_viewer.js", "https://cdn.plot.ly/plotly-2.16.1.min.js"] |
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.
Well, I have never done it before but I can give it a try. I'll let you know if I need any help. It should not be a problem to commit your changes first, right? (by the way, is it ok if I batch the smaller ones?)
I'm happy to make this change, the asset is definitely very large, but maybe it's not so popular to have to rely on an external service for this module. Maybe a solution where the user can provide a local copy as a fallback would be useful? I guess it would be a niche situation and not work the effort, but I thought I'd mention it.
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.
You can commit GitHub suggestions individually or batched. Your decision!
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.
Maybe a solution where the user can provide a local copy as a fallback would be useful? I guess it would be a niche situation and not work the effort, but I thought I'd mention it.
Yeah, I don't think we are intending for signac-dashboard to be fully usable offline. The core features are baked in, but I don't think it's necessary to include large assets for specific modules like this one in the distributed package. It increases the size of the signac-dashboard repo and downloaded package, and has a high likelihood of going out of date.
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.
@javierbg to rewrite the history of the branch perform an "interactive rebase" and remove the commits that added the large file.
The dashboard developers could alternately squash merge this branch to prevent the large file addition to the history.
Codecov Report
@@ Coverage Diff @@
## master #163 +/- ##
==========================================
- Coverage 73.83% 73.64% -0.20%
==========================================
Files 20 21 +1
Lines 795 846 +51
==========================================
+ Hits 587 623 +36
- Misses 208 223 +15
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Explicit tests aren't needed -- the testing framework is pretty weak right now, and this should be automatically covered by the "kitchen sink" tests. However, an example would be good to include. |
I agree with Bradley. This seems very useful. Thank you for the implementation! If you could include an example, I'll also test it locally on my machine. |
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.
Minor changes for #163
Co-authored-by: Bradley Dice <[email protected]>
I'm not familiarized with Flask, so when it came to add the routes and assets I just used other modules as reference (I think it was the When adding the Plotly CDN URL I realized that the |
c55b48f
to
a3afa94
Compare
Co-authored-by: Bradley Dice <[email protected]>
a3afa94
to
c55b48f
Compare
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.
Thanks for the addition. However, you need to protect access to the new routes with flask_login
.
I'm not able to add a code suggestion for this as your module does not add routes with the same pattern as the others. See the changes in #158 for examples.
|
||
|
||
def plot_viewer_asset(filename): | ||
try: |
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.
Protect this route from access by unauthenticated users.
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.
Thanks! That should work to protect the new route.
Co-authored-by: Bradley Dice <[email protected]>
839d41b
to
6ebebf9
Compare
6ebebf9
to
a898191
Compare
@@ -0,0 +1,12 @@ | |||
function draw_plot(element) { | |||
data = JSON.parse(element.getAttribute("data-plotly-data")); |
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.
Maybe the card HTML can contain a REST endpoint, and fetch the data with a second call? That way we don't have to generate and include all the raw data in the HTML page. This should help a lot with page responsiveness. You can see examples of REST calls in other modules:
- https://github.com/glotzerlab/signac-dashboard/blob/master/signac_dashboard/templates/notes/js/notes.js
- https://github.com/glotzerlab/signac-dashboard/blob/master/signac_dashboard/templates/document_editor/js/document_editor.js
If you need help with this, let me know.
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.
I have implemented this in 226111e. The page loading is way more responsive now.
Still, I'm a total newbie with Flask, so a thorough review is needed.
My main concerns are:
- I have had to create a module identifier so that a different endpoint is created for each instance of the
PlotlyView
module. I decided to hash theid(self)
which should work, but has the disadvantage that each time the dashboard is launched the URLs change. I don't think this is a huge problem, but I feel like there is a better way to do this. - For each added instance of the module, the
register
method is called. However, the assets URLs should only be added once. If you try to do it multiple times, the second time around the module is not registered. I have solved this with a class attributePlotlyViewer._assets_url_registered
that avoids this duplication. Still, I feel like this solution is somewhat hacky.
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.
Now instead of passing the data as HTML attributes a REST endpoint has been set up so that the page is rendered quickly and the client can fetch the data with a GET request
The Project.id and Job.id properties were not available in signac 1.0.0. The fix changes it to use the get_id() method in both cases.
for more information, see https://pre-commit.ci
Description
This pull request adds a new module to the dashboard for showing interactive plots in the browser.
Motivation and Context
See issue #162
Checklist: