Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Updatting a geo map

Hello,

I want to update a map by displaying data from a crossfilter in
Here is the code:

df=pd.read_csv("C:\Users\ASUS X541U\Downloads\query.csv")
df1=df.iloc[:,[0,1,2,3,4,11]]
df1=df1.dropna(axis=0, how='any')
df1.columns=['Date','lat','long','depth','mag','id']

dd=df1.values.tolist()
data=np.array(dd)


app = dash.Dash(__name__)
app.layout = html.Div()
app.config['suppress_callback_exceptions']=True





df1['text'] = df1['Date'] + '<br>Magnitude ' + df1['mag'].astype(str)+'<br>Depth' + 
df1['depth'].astype(str)
scale = 5000

data = [ dict(
    type = 'scattergeo',
    locationmode = 'country names',
    lon = df1['long'],
    lat = df1['lat'],
    text = df1['text'],
    mode = 'markers',
    marker = dict(
        size = 8,
        opacity = 0.8,
        reversescale = True,
        autocolorscale = False,
        line = dict(
            width=1,
            color='rgba(102, 102, 102)'
        )
    ))]
 layout = dict(
    title = 'Evenements sismiques',
    colorbar = True,
    geo = dict(
        projection=dict( type='world map' ),
        showland = True,
        landcolor = "rgb(250, 250, 250)",
        subunitcolor = "rgb(217, 217, 217)",
        countrycolor = "rgb(217, 217, 217)",
        countrywidth = 0.8,
        subunitwidth = 0.5
    ),
 )

    
fig = dict( data=data, layout=layout )

        
 figcl = dict(data=data2, layout=layout)
 app.layout  = html.Div([
       

 html.Div([
        dcc.Dropdown(
            id='crossmap',
            options=[{'label': i, 'value': i} for i in catalogues],
            value='USGS'
        )
    ,

        dcc.Graph(id='graph',figure=fig,style={"float":"left","width":"50%"}),


        ]),
])

Here is the callback with the update function :
@app.callback(
dash.dependencies.Output(‘graph’, ‘figure’),
[dash.dependencies.Input(‘crossmap’, ‘value’),
])
def update_graph(cat):
data_map=[]
if cat == ‘USGS’:
df=pd.read_csv(“C:\Users\ASUS X541U\Downloads\query.csv”)
df1=df.iloc[:,[0,1,2,3,4,11]]
if cat == ‘ISC’:
df = pd.read_csv(“‪C:\Users\ASUS X541U\Desktop\Catalogues\isc-gem-suppl.csv”)
df1=df.iloc[:,[0,1,2,7,10]]
df1.columns=[‘Date’,‘lat’,‘long’,‘depth’,‘mag’,‘id’]
df1=df1.dropna(axis=0, how=‘any’)
trace1 = {
“lat”:df1[‘lat’] ,
“lon”: df1[‘long’],
“marker”: {
“autocolorscale”: False,
“line”: {
“color”: col[i],
“width”: 0.5
},
“opacity”: 0.8,
“reversescale”: True,
“size”: 8
},
“mode”: “markers”,
“type”: “scattergeo”
}
data_map=[trace1]
layout = dict(
title = ‘ISC’,
colorbar = True,
geo = dict(
projection=dict( type=‘world map’ ),
showland = True,
landcolor = “rgb(250, 250, 250)”,
subunitcolor = “rgb(217, 217, 217)”,
countrycolor = “rgb(217, 217, 217)”,
countrywidth = 0.8,
subunitwidth = 0.5
),
)

     return {
        'data': data_map,
        'layout': layout
        }
                
   if __name__ == '__main__':
    app.run_server(debug=True, port=8051)