-
Notifications
You must be signed in to change notification settings - Fork 2.2k
PNG repr #634
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
PNG repr #634
Conversation
folium/map.py
Outdated
@@ -246,6 +249,26 @@ def _repr_html_(self, **kwargs): | |||
out = self._parent._repr_html_(**kwargs) | |||
return out | |||
|
|||
def _repr_png_(self): | |||
"""Displays the PNG Map in a Jupyter notebook.""" | |||
# https://github.com/ipython/ipython/issues/7899#issuecomment-76541102 |
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.
The notebook will run all _repr_*_
methods and, b/c this one can be slow, we don't really want it to be called without the user request. Not sure yet if this should be a _repr_png_
of just a to_png()
method.
folium/map.py
Outdated
driver.maximize_window() | ||
# Ignore user map size. | ||
driver.execute_script("document.body.style.width = '100%';") | ||
png = driver.get_screenshot_as_png() |
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.
We probably want to "sleep" here for a few seconds to allow for the tiles to render.
Maybe that should be a kwargs
.
with tempfile.NamedTemporaryFile(suffix=".html") as f: | ||
fname = f.name | ||
self.save(fname) | ||
driver = selenium.webdriver.PhantomJS(service_log_path=os.path.devnull) |
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.
Should probably add a try/except
clause here to test for PhantomJS
.
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.
Actually the default error message from selenium
is quite good. No need to override it.
Now a deprecation warning appears: So this is likely to break soon. |
Thanks for the heads up! I'm already trying to fix this for the |
Hi, I've been trying to use this for a project, and while it works locally, if I build my application into a docker image or try to run it from a Google Cloud Compute instance, it fails. It looks like it's trying to contact one of the dependent services (there are a number of script, css, etc embeds in the the generated HTML) but one of those fails to return any data. Unfortunately, the exceptions provided do not indicate which. Tracebacks (with some of the paths salted) below.
|
@nderen please don't post this in an old PR, open a new issue for it. You can link to this PR if needed. |
Not ready yet... just an idea for now.
See http://nbviewer.jupyter.org/gist/ocefpaf/f5a5cbdefac17985db0d89d82455e3ff
This could be used to save a png, pdf, etc.
xref.: #35