0

I want to click on one state on the first map and display, on the second map, this state with its counties.

I wrote the following code but it is not working ! Anyone has a suggestion ? Many thanks in advance !!

My data is like this (I use shapefile)

d1 = {'counties' = ["county1", "county2", "county3"], 
      'state' : ["state1", "state2", "State2"],
      'lat': [1, 2, 4], 'long': [3, 4, 5]}
ds1 = ColumnDataSource(d1)

Then, I created one ColumnDataSource for each index, these contain all the counties making up the state to which the county in question belongs (I think this will help me build map2 showing a state and its counties. But maybe it is not the right way do to so!)

row_index = []
column_ds = []
for index in range(len(d1)-1):
    row_index.append(index)
    state_name = dep_df.loc[index, 'state']
    d2 = d1[d1.state == state_name]
    ds2 = ColumnDataSource(d2)
    column_ds.append(ds2)

dict_index_datasource = dict(map(lambda i,j : (i,j) , row_index,column_ds))

I create my two maps : the first one map1, the second : map2

code = '''var selected_index = cb_data.index.selected.indices[0];
temp_ds2 = dict_index_datasource[selected_index];
ds2.data = temp_ds2;
ds2.data.change.emit();'''

map1.select(TapTool).callback = CustomJS(args = {'dict_index_datasource': dict_index_datasource, 
                                                 'ds2': ds2}, code = code)
        
layout1 = layout([row([p_metropole, p_one_dep])])
map_name = f"dashboard.html"
output_file(map_name)
save(layout1) 

When I click on one county on map1, nothing change on map2 : the state in which the county clicked on does not appear.

mosc9575
  • 5,618
  • 2
  • 9
  • 32

0 Answers0