posit-dev / py-shinywidgets

Render ipywidgets inside a PyShiny app
MIT License
47 stars 5 forks source link

Widget support for Folium and pivis.Network outputs #81

Closed absripad closed 1 year ago

absripad commented 1 year ago

Description

Looking for way to display outputs from Folium and pivis.Network on Shiny

Code attached. Works for ipyleaflet maps.

import folium from shiny import * from shinywidgets import output_widget, register_widget, render_widget import ipyleaflet as L

m = folium.Map(location=[45, -122], zoom_start = 12) m.save('map.html')

app_ui = ui.page_fluid(
ui.output_text_verbatim("txt"), output_widget('ddd') )

def server(input, output, session):
@output @render.text def txt(): return 'Map from Folium'

@output
@render_widget
def ddd():
    return m()
    # return m     # Does NOT Work
    # return m._repr_html_()     # Does NOT Work
    # return L.Map(center=(51, 0), zoom=12)    # WORKS!

app = App(app_ui, server)

cpsievert commented 1 year ago

Duplicate of #71 and #63 (please see this comment https://github.com/posit-dev/py-shinywidgets/issues/71#issuecomment-1815433007)