1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] No plotly graph in folium popup

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024 às 12:52.

  1. Stack

    Stack Membro Participativo

    I am trying to embed a plotly barchart in a folium popup.

    This is how I proceed in Google Colab :

    # basic map :
    map = folium.Map( location = [ 47.9060278 , 1.9020353 ] , zoom_start = 6, tiles = 'OpenStreetMap' )

    # html file of plotly barchart :

    fig = px.bar( a003_pdv_ca_his , x = 'mm' , y = 'ca' )

    file_path = '/content/drive/MyDrive/Colab Notebooks/Data/a003_pdv_ca_his_20001.html'

    fig.write_html( file_path )

    with open( file_path , encoding = 'utf-8' ) as f :
    html = f.read()

    # html in iframe :
    iframe = branca.element.IFrame( html = html , width = 500 , height = 300 )

    # folium popup from iframe :
    popup = folium.Popup( iframe , max_width = 500 )

    # add marker to the map :
    folium.Marker( location = [ row.lat , row.lon ] , popup = popup , icon = folium.Icon( color = row.ins_clr ) ).add_to( map )

    map


    Infortunately the popup is empty. I see the barchart when opening the html file.

    Has anyone an idea to fix this ? It might be of problem concerning the iframe...

    Thanks for your help on that topic.

    Continue reading...

Compartilhe esta Página