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

Feature/shiny v0.7.0 #34

Merged
merged 16 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .examples/circle_layer/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from maplibre import Layer, Map, output_maplibregl, render_maplibregl
from maplibre import Layer, Map, MapOptions, output_maplibregl, render_maplibregl
from maplibre.basemaps import Carto
from maplibre.shiny import MapLibreRenderer
from shiny import App, reactive, render, ui

circle_layer = Layer(
"circle",
id_="counties",
type="circle",
id="counties",
source={
"type": "geojson",
"data": "https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/arc/counties.json",
Expand All @@ -27,9 +28,9 @@


def server(input, output, session):
@render_maplibregl
@MapLibreRenderer
async def map():
map_ = Map(style=Carto.POSITRON, center=center, zoom=7)
map_ = Map(MapOptions(style=Carto.POSITRON, center=center, zoom=7))
map_.add_layer(circle_layer)
return map_

Expand Down
10 changes: 10 additions & 0 deletions .examples/shiny_express/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from maplibre import Map
from maplibre.shiny import MapLibreRenderer
from shiny.express import ui

ui.h1("Hello world!")


@MapLibreRenderer
def mapylibre():
return Map()
2 changes: 2 additions & 0 deletions maplibre/server.py → _obsolete/server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### DEPRECATED: see 'shiny.py'

from __future__ import annotations

from shiny.render.transformer import (
Expand Down
11 changes: 2 additions & 9 deletions docs/examples/every_person_in_manhattan/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@

import pandas as pd
import shapely
from maplibre import (
Layer,
LayerType,
Map,
MapContext,
MapOptions,
output_maplibregl,
render_maplibregl,
)
from maplibre import (Layer, LayerType, Map, MapContext, MapOptions,
output_maplibregl, render_maplibregl)
from maplibre.basemaps import Carto
from maplibre.controls import ScaleControl
from maplibre.sources import GeoJSONSource
Expand Down
2 changes: 1 addition & 1 deletion docs/layers.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The `paint` and `layout` properties for the layers depend on the [type](/api/layer/#pymaplibregl.LayerType) of the layer.
The `paint` and `layout` properties for the layers depend on the [type](../api/layer/#maplibre.LayerType) of the layer.
They are passed as a `dict` corresponding to the [Layer Style Spec](https://maplibre.org/maplibre-style-spec/layers/).

For example, to set the radius and the color for a circle layer, the `paint` property looks like this:
Expand Down
5 changes: 2 additions & 3 deletions maplibre/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from .controls import ControlPosition, ControlType

# from .ipywidget import MapWidget
from .layer import Layer, LayerType
from .map import Map, MapOptions
from .mapcontext import MapContext
from .server import render_maplibregl
from .renderer import MapLibreRenderer
from .renderer import MapLibreRenderer as render_maplibregl
from .ui import output_maplibregl
13 changes: 13 additions & 0 deletions maplibre/renderer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from htmltools import Tag
from shiny.render.renderer import Renderer

from .map import Map
from .ui import output_maplibregl


class MapLibreRenderer(Renderer[Map]):
def auto_output_ui(self) -> Tag:
return output_maplibregl(self.output_id, height=600)

async def transform(self, value: Map) -> dict:
return {"mapData": value.to_dict()}
7 changes: 5 additions & 2 deletions maplibre/ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
### TODO: move to 'shiny.py'

from __future__ import annotations

from htmltools import HTMLDependency
from htmltools import HTMLDependency, Tag

from shiny import ui
from shiny.module import resolve_id

Expand All @@ -24,7 +27,7 @@
)


def output_maplibregl(id_: str, height: [int | str] = 200):
def output_maplibregl(id_: str, height: [int | str] = 200) -> Tag:
if isinstance(height, int):
height = f"{height}px"

Expand Down
1,297 changes: 632 additions & 665 deletions poetry.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "maplibre"
version = "0.1.4"
version = "0.1.4.1"
description = "Python bindings for MapLibre GL JS"
authors = ["Stefan Kuethe <[email protected]>"]
readme = "README.md"
Expand All @@ -11,10 +11,10 @@ include = [

[tool.poetry.dependencies]
python = ">=3.9,<4"
shiny = "^0.6.1"
htmltools = "^0.5.1"
jinja2 = "^3.1.3"
pydantic = "^2.5.3"
shiny = ">=0.7.0"
htmltools = ">=0.5.1"
jinja2 = ">=3.1.3"
pydantic = ">=2.5.3"
anywidget = ">=0.9.0"
pandas = {version = "^2.1.4", optional = true}
geopandas = {version = "^0.14.2", optional = true}
Expand Down
Loading