RuKrei
(Rudi Kreidenhuber)
January 24, 2021, 12:29am
1
Dear everybody,
has anybody here ever tried to add .htmls generated with plotly to mne.Report()?
plotly offers a convenient way of saving interactive plots to html via figure.write_html(“foo.html”).
I tried adding the interactive plot as a figure via:
report.add_figs_to_section(figure) → doesn’t work, as mne tries to render a 3d figure and fails
and
report.add_htmls_to_section(“foo.hmtl”) → doesn’t work, as the figure/html doesn’t show up (but caps etc. are present)
Does anybody have an idea how to circumvent this?
I think it would be nice to have interactive figures/ a little bit of plotlys power in mne.report.
Thanks for your help!
Best
Rudi K
mainakjas
(Mainak Jas)
January 24, 2021, 5:07am
2
Hi Rudi,
I suspect that plotly has javascript code in the header that don’t work when you use report.add_htmls_to_section
. Not sure if there is an easy way without understanding the architecture of the report.
FWIW, I tried using mpld3 for interactivity in the report long ago and it seemed to have worked easily .
So maybe you can try that route with add_htmls_to_section
Hope that helps,
Mainak
richard
(Richard Höchenberger)
January 24, 2021, 9:33am
3
Yes, this is my guess too. I recently added a Report.add_custom_css
method that allows one to add custom CSS to the HTML <head>
; in the same way, we could add a method that would do a similar thing for JavaScript. You’d still have to manually extract the relevant parts of the plotly-generated HTML before inserting them into the report.
agramfort
(Alexandre Gramfort)
January 24, 2021, 2:54pm
4
can you share a code snippet to start where you stopped?
Alex
RuKrei
(Rudi Kreidenhuber)
January 24, 2021, 6:25pm
5
@agramfort : are you asking @mainakjas or do you want me to provide a minimal working example?
agramfort
(Alexandre Gramfort)
January 24, 2021, 6:52pm
6
If you can do it it’s great
Then I will see what I can do
Alex
RuKrei
(Rudi Kreidenhuber)
January 24, 2021, 8:33pm
7
no problem, here is a gist as a starter kit to look into this:
plotly_to_mne_report.py
"""
Thank you all for looking into this.
What I am working on here is a pipeline to aid in diagnosis of epilepsy in a clinical setting (Long term video EEG monitoring).
The goal is to extract Annotations of an EEG-file and visualize them in a useful manner.
The number of Annotations might be anything between only a few to a few hundred. Data should be visualized and also shown in
tabular form.
Plotly is an obvious choice, since its defaults handle this dynamic setting well.
I copypasted some parts of the code in order to reproduce a visualization from the pipeline.
This file has been truncated. show original
Thanks for your help!
Rudi
agramfort
(Alexandre Gramfort)
January 25, 2021, 8:17am
8
just do this:
report.add_htmls_to_section(fig.to_html(full_html=False), section=“test”, captions=“test_add_htmls”)
and it works
Alex
RuKrei
(Rudi Kreidenhuber)
January 25, 2021, 9:43am
9
Hmm, so easy and yet too hard for me.
Thank you, Alex, it works perfectly
Rudi