TiesdeKok / ipystata

Enables the use of Stata together with Python via Jupyter (IPython) notebooks.
192 stars 68 forks source link

Inline graph images broken #35

Open kpfoley opened 6 years ago

kpfoley commented 6 years ago

I've just started using IPyStata and it's great, but the inline graphs were displaying as blank / gray boxes in the jupyter notebook. My install is a little unusual so I'm not sure if others have run into the same problem, but it looks like it's related to this issue from Jupyter. If I understand correctly there was a security-minded fix to Jupyter that prevents .pdf images from being loaded inline in notebooks. This seems to be the case, since I couldn't load pdf images directly from the Jupyter project folder but was able to load png images. Unfortunately, unix/linux Stata is unable to save graphs to png.

I've implemented a kludgy fix on my installation which uses imagemagick to convert temp_file.pdf to temp_file.png before loading the graph in the notebook with IFrame, but it doesn't seem like a good solution to the problem since it introduces system calls and adds a non-Python dependency.

Has anyone else run into this problem?

My setup:

Jupyter 4.4.0 Jupyter-notebook 5.6.0 (and 5.7.0dev0) IPython 6.4.0 Python 3.6.4 latest IPyStata chromebook / ChromeOS 67

TiesdeKok commented 6 years ago

Thanks for the heads-up @kpfoley!

I have not encounted this problem before, but I completely acknowledge that the PDF solution is not great.

It seems that @kylebarron figured out a solution by using .svg files for his stata_kernel, I might be able to replicate his solution and implement it into ipystata. If we can circumvent the problem with png files using svg files then I could avoid PDFs all together solving the problem.

For my own reference, this is the relevant code: stata_kernel commit

ozak commented 4 years ago

Any updates on this? I just tried creating a figure and get no output inline. Also if I run one of your examples

%%stata -gr
use http://stats.idre.ucla.edu/stat/stata/notes/hsb2, clear
graph twoway scatter read math, name(a, replace) title("Graph a")

graph twoway scatter math science, name(b, replace) title("Graph b")

I get

image

TiesdeKok commented 4 years ago

Unfortunately not, never got around to it and consequently forgot about it. I've set a reminder to look at this once my schedule clears up in a couple of weeks. Once I looked into it I will update this issue thread.

Thanks for the reminder!

ozak commented 4 years ago

Thanks! In the meantime a workaround is to save the file and then import it into the notebook.