Srn
Srn

Reputation: 1

Dash-leaflet error using dash_table and geopandas

I am a begginer to use dash-leaflet. I try to make a dashboard with displaying a (geo)DataFrame on a dash_table and on a dash_leaflet.Map I manage to do one or the other but not the both.

In this example below, I display the dash_table and it works :

import dash
from dash import dcc
from dash import html
import pandas as pd

df = pd.DataFrame({'id':[1,2],
 'lon':[42, 42.1],
 'lat':[2, 2.1]}
)
columns = [{'name': col, 'id': col} for col in df.columns]
app = dash.Dash(__name__)
app.layout = html.Div([    

    html.H1('Hello Dash'),
    
    dash.dash_table.DataTable(id='dashTable', 
                              data = df.to_dict(orient='records'), 
                              columns = columns)
    
    ])

app.run_server(debug=True, use_reloader=False)

In this example below, I just create a GeoDataFrame, without displaying it anywhere :

import dash
from dash import html
import pandas as pd
import geopandas as gpd



df = pd.DataFrame({'id':[1,2],
 'lon':[42, 42.1],
 'lat':[2, 2.1]}
)

columns = [{'name': col, 'id': col} for col in df.columns]
gdf = gpd.GeoDataFrame(
    df, geometry=gpd.points_from_xy(df['lon'], df['lat']))

app = dash.Dash(__name__)
app.layout = html.Div([
    
    html.H1('Hello Dash'),
    
    dash.dash_table.DataTable(id='dashTable', 
                              data = df.to_dict(orient='records'), 
                              columns = columns)
    
    ])

app.run_server(debug=True, use_reloader=False)

and I got an error on my 127.0.0.1:8050 on Chrome : "Error loading layout"

Upvotes: 0

Views: 244

Answers (1)

Srn
Srn

Reputation: 1

I found the problem was that my dataframe df is erased by the geodataframe. So the Json in dataTable got wrong values with geometries

Upvotes: 0

Related Questions