Skip to content

Explore Plugin

The tangram_explore plugin provides a quick way to spawn visualise arbitrary dataframes (polars/pandas) on the map.

It is strongly inspired lonboard.

Overview

  • Uses arro3 to convert any dataframe supporting the Arrow C Stream Interface into Parquet bytes.
  • Data is stored on the Python side and metadata is broadcasted to all connected clients
  • Browser fetches the Parquet data via HTTP, decodes it using parquet-wasm, and renders it using deck.gl

Future Work

  • Support for LineString and Polygon layers (requires GeoArrow processing).
  • Drag-and-drop file upload in the sidebar.
  • Synchronization

Examples

Basic

Spawn two intersecting diagonal lines as 100 scatter points, centred at (0, 0).

map interface

# ruff: noqa: F704, E402
# %%
import numpy as np
import polars as pl
import tangram_core
from tangram_core.config import CoreConfig

runtime = tangram_core.Runtime(
    config=tangram_core.Config(core=CoreConfig(plugins=["tangram_explore"]))
)
await runtime.start()
# %%
from tangram_explore import ScatterLayer, Session

session = Session(runtime.state)

x = np.linspace(-13, 13, 100)
# %%
await session.push(
    ScatterLayer(
        pl.DataFrame({"longitude": x, "latitude": x}),
        fill_color="#027ec7",
        label="NE-SW",
    )
)
# %%
await session.push(
    ScatterLayer(
        pl.DataFrame({"longitude": x, "latitude": -x}),
        fill_color="#be4d5e",
        label="NW-SE",
    )
)
# %%
await runtime.stop()
# %%
import asyncio

import numpy as np
import polars as pl
import tangram_core
from tangram_core.config import CoreConfig
from tangram_explore import ScatterLayer, Session


async def main() -> None:
    async with tangram_core.Runtime(
        config=tangram_core.Config(core=CoreConfig(plugins=["tangram_explore"]))
    ) as runtime:
        session = Session(runtime.state)

        x = np.linspace(-13, 13, 100)
        await session.push(
            ScatterLayer(
                pl.DataFrame({"longitude": x, "latitude": x}),
                fill_color="#027ec7",
                label="NE-SW",
            ),
        )
        await session.push(
            ScatterLayer(
                pl.DataFrame({"longitude": x, "latitude": -x}),
                fill_color="#be4d5e",
                label="NW-SE",
            )
        )
        await runtime.wait()


if __name__ == "__main__":
    asyncio.run(main())