kylebarron / keplergl_cli

One-line geospatial data visualization using Kepler.gl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

export keplergl html string or save vis.html to a certain directory

waterchinap opened this issue · comments

  • Kepler Quickvis version:
  • Python version:3.8
  • Operating System:manjaro

Description

Describe what you were trying to get done.
I am using fastapi(flask) to develop an app. hope to export the keplergl html to the jinja2 template.
map_1 = Visualize(df_last, api_key=mtoken)
the code works fine in jupyter notebook, but can not run in pycharm.

wondering if keplergl_cli can provide the following two ways to use kepler in an app:

  1. export a html string, which can be put in a jinja2 template.
  2. save a vis.html file in the app root. (keplergl_cli save the html file in a /tmp/(randam)/vis.html)

Tell us what happened, what went wrong, and what you expected to happen.
map_1 = Visualize(df_last, api_key=mtoken)
got an error:TypeError: Object of type date is not JSON serializable

What I Did

File "<ipython-input-18-8de58dad3128>", line 105, in fig_world
    map_1 = Visualize(df_last, api_key=mtoken)
  File "/home/eric/miniconda3/envs/myenv/lib/python3.8/site-packages/keplergl_cli/keplergl_cli.py", line 68, in __init__
    self.html_path = self.render(read_only=read_only)
  File "/home/eric/miniconda3/envs/myenv/lib/python3.8/site-packages/keplergl_cli/keplergl_cli.py", line 146, in render
    self.map.save_to_html(file_name=path, read_only=read_only)
  File "/home/eric/miniconda3/envs/myenv/lib/python3.8/site-packages/keplergl/keplergl.py", line 168, in save_to_html
    keplergl_data = json.dumps({"config": config_to_add, "data": data_to_add, "options": {"readOnly": read_only, "centerMap": center_map}})
  File "/home/eric/miniconda3/envs/myenv/lib/python3.8/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/home/eric/miniconda3/envs/myenv/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/eric/miniconda3/envs/myenv/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/eric/miniconda3/envs/myenv/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type date is not JSON serializable

Your data needs to be JSON serializable. If you have data as Python date objects, you need to coerce to a string before saving.

Thank you so much!
it work, save me a few hour.
cannot believe I did note notice this.