Skip to content
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

Give _repr_html_ higher precedence than _repr_png_ #1191

Closed
MarcSkovMadsen opened this issue Mar 26, 2020 · 6 comments
Closed

Give _repr_html_ higher precedence than _repr_png_ #1191

MarcSkovMadsen opened this issue Mar 26, 2020 · 6 comments
Labels
type: discussion Requiring community discussion

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Mar 26, 2020

My Pain

Trying to help with this question https://discourse.holoviz.org/t/panel-and-folium-do-they-mix/342/2.

I can see that a Folium Map has a repr_html method and as such should be supported in Panel.

But when using it in a Column I get an unexpected TypeError

import folium as fm
import panel as pn

in_lat = 20.5936832
in_long = 78.962883
in_map = fm.Map(location=[in_lat, in_long], zoom_start=5)

pn.Column(in_map).servable()
$ python -m panel serve 'examples\folium_issue.py' --dev --show
2020-03-26 04:27:12,561 Starting Bokeh server version 1.4.0 (running on Tornado 6.0.3)
2020-03-26 04:27:12,591 User authentication hooks NOT provided (default user enabled)
2020-03-26 04:27:12,626 Bokeh app running at: http://localhost:5006/folium_issue
2020-03-26 04:27:12,631 Starting Bokeh server with process id: 20972
2020-03-26 04:27:19,374 Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x0000001452A73E08>: argument should be a bytes-like object or ASCII string, not 'NoneType'
File "base64.py", line 46, in _bytes_from_decode_data:
"string, not %r" % s.__class__.__name__) from None Traceback (most recent call last):
  File "C:\repos\private\panel\.venv\lib\site-packages\bokeh\application\handlers\code_runner.py", line 179, in run
    exec(self._code, module.__dict__)
  File "C:\repos\private\panel\examples\folium_issue.py", line 8, in <module>
    pn.Column(in_map).servable()
  File "C:\repos\private\panel\panel\viewable.py", line 243, in servable
    self.server_doc(title=title)
  File "C:\repos\private\panel\panel\viewable.py", line 600, in server_doc
    model = self.get_root(doc)
  File "C:\repos\private\panel\panel\viewable.py", line 536, in get_root
    root = self._get_model(doc, comm=comm)
  File "C:\repos\private\panel\panel\layout.py", line 136, in _get_model
    objects = self._get_objects(model, [], doc, root, comm)
  File "C:\repos\private\panel\panel\layout.py", line 126, in _get_objects
    child = pane._get_model(doc, root, model, comm)
  File "C:\repos\private\panel\panel\pane\markup.py", line 43, in _get_model
    model = self._bokeh_model(**self._get_properties())
  File "C:\repos\private\panel\panel\pane\image.py", line 95, in _get_properties
    data = base64.b64decode(data)
  File "C:\Users\masma\AppData\Local\Programs\Python\Python37\lib\base64.py", line 80, in b64decode
    s = _bytes_from_decode_data(s)
  File "C:\Users\masma\AppData\Local\Programs\Python\Python37\lib\base64.py", line 46, in _bytes_from_decode_data
    "string, not %r" % s.__class__.__name__) from None
TypeError: argument should be a bytes-like object or ASCII string, not 'NoneType'

Additional Context

This works though

import folium as fm
import panel as pn

in_lat = 20.5936832
in_long = 78.962883
in_map = fm.Map(location=[in_lat, in_long], zoom_start=5)

pn.pane.HTML(in_map, height=400, width=400).servable()

image

@MarcSkovMadsen MarcSkovMadsen added the TRIAGE Default label for untriaged issues label Mar 26, 2020
@MarcSkovMadsen
Copy link
Collaborator Author

Additional Context

I've also added a feature request to support Folium via a Panel pane. See #1192

@philippjfr
Copy link
Member

IMO this is Folium's fault, they define a _repr_png but that returns None.

@MarcSkovMadsen
Copy link
Collaborator Author

But there is also an repr_html method should that no be prioritized higher than the repr_png ?

@jbednar
Copy link
Member

jbednar commented Apr 1, 2020

The principle in Panel is normally that the richest output is prioritized higher, and I consider HTML to be richer than PNG in capabilities, so I would agree. Also worth filing as a bug report on Folium, though!

@philippjfr
Copy link
Member

_repr_png_ apparently doesn't work unless png_enabled is passed to the constructor. For now I've solved this by adding a very basic Folium pane which has higher priority but is just an HTML wrapper.

@philippjfr philippjfr added type: discussion Requiring community discussion and removed TRIAGE Default label for untriaged issues labels Apr 9, 2020
@philippjfr philippjfr changed the title Folium TypeError: argument should be a bytes-like object or ASCII string, not 'NoneType' Give _repr_html_ higher precedence than _repr_png_ Apr 9, 2020
@philippjfr
Copy link
Member

Given that this hasn't been a re-occuring issue for other panes and the Folium wrapper works well I'll close. Happy to reconsider if we find further problematic cases though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: discussion Requiring community discussion
Projects
None yet
Development

No branches or pull requests

3 participants