Open CurtLH opened 6 years ago
I have a very similar problem which solutation is probably the same as to your problem. Generally I think it is impossible to embed interactive bokeh plots in the github README file. Github filters any script tags and similar stuff out (second step described here) so I think even if pweave would produce something sensible when exporting to markdown it shouldn't work on github. Alternativly you could include a PNG rendering from the bokeh plot, which of course is then no longer interactive, or link to a github pages page with a bokeh plot. Also currently in pweave there is as far as I see now code to generate bokeh plots but for HTML (see here)
My personal problem is as following: I want to generate HTML and latex (pdf) reports from a single pweave documents with included bokeh plots. HTML of course already works via the pweave bokeh "hooks"/functions. Until now I exported the bokeh plot as SVG and then used inkscape to export to pdf and included that as a picture in the latex file (theoretically one can also directly include svgs in pdfs/latex but I found that more complex than actually doing the conversion SVG->PDF myself). Now I want to use pweave to archieve this. Ofcourse pweave shouldn't include this pipeline by default (I think in bokeh SVG export is somehow a second-class citizen, so basing a pweave feature on it doesn't seem like a good idea) but I tried to "hack" this feature into pweave myself.
I couldn't really find documentation on how to extend python objects in such a way that pweave understands them. I would have thought that the ipython rich display system is used to convert python objects to the output format if a _repr_{format}
function is available, but this doesn't seem to be the case? I tried to dive into pweave to see how the conversion is handled but I couldn't really find the code. Is the ipython rich display system used? If no, how can I customize my own python classes such that they work nicely with pweave?
This should also "solve" the OPs problem in the sense that he could write an extension to first render bokeh plots to png and then include these into the markdown file. This is why I wrote this in to this issue instead of creating a new one.
I struggle to generate a HTML report with a bokeh plot from a md file containing the documentation example cited above.
I tried
pweave -f md2html sample.pmd
but I get in the html report only the python code block without any plot. I tried to play with the following code chunks options without success
, echo=True, evaluate=True, include=True
I assume there is a problem generating the plot as the figures directory created is empty.
Any hint to help?
@ylaizet Are you using pweave.bokeh.output_pweave()
and pweave.bokeh.show(plot)
as shown in the documentation?
Yes I took exactly the code of the documentation, as shown in CurtLH post above (between triple backquotes not visible here), that's why I ask; I did it on a fresh virtualenv install (python3).
Here is what I did under Ubuntu 18.04:
mkvirutalenv pweave -p /usr/bin/python3
pip install pweave
# copy paste the documentation bokeh example code in a bokeh.pmd file
pweave -f md2html bokeh.pmd
Here is the terminal output
status
Processing chunk 1 named None from line 17
Weaved bokeh.pmd to bokeh.html
The html file as the codeblock but no plot :-(
Here is the pip freeze result in case it helps
astroid==2.1.0
backcall==0.1.0
bleach==3.1.0
bokeh==1.0.4
decorator==4.3.0
defusedxml==0.5.0
entrypoints==0.3
ipykernel==5.1.0
ipython==7.2.0
ipython-genutils==0.2.0
isort==4.3.4
jedi==0.13.2
Jinja2==2.10
jsonschema==2.6.0
jupyter-client==5.2.4
jupyter-core==4.4.0
lazy-object-proxy==1.3.1
Markdown==3.0.1
MarkupSafe==1.1.0
mccabe==0.6.1
mistune==0.8.4
nbconvert==5.4.0
nbformat==4.4.0
numpy==1.16.0
packaging==19.0
pandocfilters==1.4.2
parso==0.3.2
pexpect==4.6.0
pickleshare==0.7.5
Pillow==5.4.1
pkg-resources==0.0.0
prompt-toolkit==2.0.7
ptyprocess==0.6.0
Pweave==0.30.3
Pygments==2.3.1
pylint==2.2.2
pyparsing==2.3.1
python-dateutil==2.7.5
PyYAML==3.13
pyzmq==17.1.2
six==1.12.0
testpath==0.4.2
tornado==5.1.1
traitlets==4.3.2
typed-ast==1.2.0
wcwidth==0.1.7
webencodings==0.5.1
wrapt==1.11.1
I figured out that I had also a problem in rendering the output of & chunks as in issue #132 . As the problem seemed to come from the version of ipykernel, I gave it a try by downgrading it to ipykernel==4.10.0
and it worked, both code chunk result rendering and bokeh plot.
Here is the install process as a workaround until it's fixed:
mkvirtualenv pweave -p /usr/bin/python3
pip install ipykernel==4.10.0
pip install pweave
pip install bokeh
List of installed modules and versions with ipykernel==4.10.0
pip freeze
backcall==0.1.0
bleach==3.1.0
bokeh==1.0.4
decorator==4.3.2
defusedxml==0.5.0
entrypoints==0.3
ipykernel==4.10.0
ipython==7.2.0
ipython-genutils==0.2.0
jedi==0.13.2
Jinja2==2.10
jsonschema==2.6.0
jupyter-client==5.2.4
jupyter-core==4.4.0
Markdown==3.0.1
MarkupSafe==1.1.0
mistune==0.8.4
nbconvert==5.4.0
nbformat==4.4.0
numpy==1.16.1
packaging==19.0
pandocfilters==1.4.2
parso==0.3.2
pexpect==4.6.0
pickleshare==0.7.5
Pillow==5.4.1
pkg-resources==0.0.0
prompt-toolkit==2.0.8
ptyprocess==0.6.0
Pweave==0.30.3
Pygments==2.3.1
pyparsing==2.3.1
python-dateutil==2.7.5
PyYAML==3.13
pyzmq==17.1.2
six==1.12.0
testpath==0.4.2
tornado==5.1.1
traitlets==4.3.2
wcwidth==0.1.7
webencodings==0.5.1
I am also looking at outputing bokeh plots into Markdown but have had no luck so far.
Not sure if this is really it, but if you look at the source code of output_pweave()
, you will see that display_markdown(out, raw=True)
is commented out so it seems as it is forced to html_output()
@yportier : it works pretty well for me now. Using the examples code of the documentation with an installation with ipykernel==4.10.0, pweave and bokeh libs. Then use the pweave -f md2html tuto.md
command to generate the html file
I found that by using ipython 7.2.0 conda install ipython=7.2.0
the code line for pweave -f markdown sample.pmd
would run for me. However, the markdown file was all messy and did not show the graphs.
Using the example from the documentation, I am able to embed a bokeh plot into a HTML report, but not a markdown report. Is the feature supported and I'm just not defining the chunk correctly or possibly not calling
pweave
correctly?I want to use this to generate a markdown page for a GitHub repo, and not an HTML document. If I use
md2html
, the Bokeh plot renders as expected.Command used to generate markdown: