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

lonboard within quarto? #473

Closed
shriv opened this issue Apr 21, 2024 · 8 comments · Fixed by #474
Closed

lonboard within quarto? #473

shriv opened this issue Apr 21, 2024 · 8 comments · Fixed by #474

Comments

@shriv
Copy link
Contributor

shriv commented Apr 21, 2024

This is more of a question rather than a request for an epic! My use case is plotting traffic volumes on every street (technically "link" i.e. segments between intersections) in New Zealand within an HTML document generated by quarto. The data is too big to be rendered comfortably by leaflet-based libraries and I have to filter the data considerably to view an interactive output.

I'm wondering if lonboard can be used within a quarto document to visualise the full dataset? I see that lonboard can be used with shiny but most of my other visualisations can be output as a simple static HTML and hosted on Gitlab Pages so this option would be preferable :-)

@kylebarron
Copy link
Member

I'm not familiar with using quarto in this way. Does to_html do what you want? That saves the HTML as a file on disk. Or do you want to render the HTML with IPython as a static HTML?

@shriv
Copy link
Contributor Author

shriv commented Apr 21, 2024

The latter. I normally render the quarto document within a single html. The rendering engine for python in quarto is Jupyter and I can even render a ipynb file with quarto.. Maybe it will all be fine! Apologies, I normally use R with quarto and I haven't used it as extensively with python. I'll have a bit of a tinker and write back here :-)

@kylebarron
Copy link
Member

You can try using IPython.display.core.HTML() like I do in this PR #474

@shriv
Copy link
Contributor Author

shriv commented Apr 21, 2024

Many thanks @kylebarron..! I will try that as well 👍

@shriv
Copy link
Contributor Author

shriv commented Apr 22, 2024

Got a lonboard map running within quarto!

# this was needed because I'm using poetry within a nix environment
export QUARTO_PYTHON=$(which python)
# render the qmd file to html
quarto render test.qmd

However, it is a bit slow for all the links in the full country so I'm going to move the project to a shiny app.

image

@arthurgailes
Copy link

@shriv how did you get quarto to output the HTML properly?

@shriv
Copy link
Contributor Author

shriv commented May 2, 2024

@arthurgailes I just had the following in test.qmd before I ran quarto render test.qmd. I've put a \ before the triple backticks so that you can see all the contents in one snippet rather than multiple! :-) The \ won't be there in the actual qmd file..

---
title: "Lonboard test"
execute:
  echo: false
format: 
  html: 
    self-contained: true
jupyter: python3
---

\```{python}
# importing packages
import pandas as pd
import geopandas as gpd
import lonboard
from IPython.display import display, HTML

# geopandas option
gpd.options.io_engine = "pyogrio"
\```


\```{python}
network = gpd.read_file("data/network.gpkg")
car_vols = pd.read_csv("data/volumes_car_hourly.csv")
# join volume data to network
network_vols = network.merge(car_vols)
\```

\```{python}
layer = lonboard.PathLayer.from_geopandas(
    network_vols,
    width_min_pixels=0.8)
map_ = lonboard.Map(layers=[layer])
map_
\```


@arthurgailes
Copy link

@shriv that works, thank you very much.

kylebarron added a commit that referenced this issue May 2, 2024
Closes #473

```py
import lonboard
import geopandas as gpd

gdf = gpd.read_file(gpd.datasets.get_path('nybb'))

m = lonboard.viz(gdf)
m.as_html()
```

<img width="658" alt="image"
src="https://github.com/developmentseed/lonboard/assets/15164633/58bacf5f-e2c9-4d72-bc74-de1a6e4d04bc">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants