Conversation
|
Do you consider that a new test is needed for the module? |
bdice
left a comment
There was a problem hiding this comment.
@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
| modules.StatepointList | ||
| modules.TextDisplay | ||
| modules.VideoViewer | ||
| modules.PlotViewer |
signac_dashboard/modules/__init__.py
Outdated
| "StatepointList", | ||
| "TextDisplay", | ||
| "VideoViewer", | ||
| "PlotViewer", |
| 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.
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.
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.
You can commit GitHub suggestions individually or batched. Your decision!
There was a problem hiding this comment.
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.
@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. |
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
|
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 <bdice@bradleydice.com>
a3afa94 to
c55b48f
Compare
joaander
left a comment
There was a problem hiding this comment.
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.
Protect this route from access by unauthenticated users.
joaander
left a comment
There was a problem hiding this comment.
Thanks! That should work to protect the new route.
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
839d41b to
6ebebf9
Compare
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
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.
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.
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
PlotlyViewmodule. 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
registermethod 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_registeredthat avoids this duplication. Still, I feel like this solution is somewhat hacky.
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: