Use 2 dataframe for 1 map

Use 2 dataframe in 1 map

Hello everyone :grin:
I just began to use streamlit, and I am trying to display a map with 2 sources.
Sources :

  • adress_input : adress_input by the user (then geocoder to lat/long)
  • df_restaurant : I have a csv with restaurant lat/long

I am trying to zoom the map within the adress_input and to be able to see the point from df_restaurant

Is there anyway of doing this ? I have tried things but always it shows 2 maps and can not handle to merge 2 maps in 1.

Steps to reproduce

Code snippet:

import streamlit as st
import pandas as pd
from geopy.geocoders import Nominatim

## -- geocoder -- #
geolocator = Nominatim(user_agent="streamlit")

# SideNAR
st.markdown("# Main page 🎈")
st.sidebar.markdown("# Main page 🎈")

## -- Read raw BQ data -- ##
df = pd.read_csv("vr_extract.csv")
df.rename(columns={"lattitude": "latitude"}, inplace=True)
df.dropna(subset=['latitude', "longitude"], inplace=True), zoom=12)

# Adress
adress_input = st.text_input("Adress :", "3 Rue de Montholon, 75009 Paris")
location = geolocator.geocode(adress_input)
# Create a DataFrame with latitude and longitude
if location is not None:
    # Create a DataFrame with latitude and longitude
    data = {'latitude': [location.latitude], 'longitude': [location.longitude]}
    adress_df = pd.DataFrame(data)

    # Display the address on the map, latitude="latitude", longitude="longitude", zoom=12, use_container_width = True)
    st.write("Address not found. Please enter a valid address.")

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

1 map which will be zoomed to the adress_input and displayed at the same time the point from df_restaurant

Actual behavior:

2 maps : 1 zoom with adress_input, the other displayed the point from the df_restaurant

Thanx a lot ! :nerd_face:

Additional information

Hi @anataf

Looking at the code, since is called twice, thus there are 2 maps. Also, each call of is using 2 different dataframes.

If you can combine the 2 dataframes into 1 dataframe, perhaps via pd.concat, whereby the information for the 2 dataframes can co-exist in the same dataframe. Thus, this would only require 1 call of st.maps and therefore display 1 map.

Hope this helps!

1 Like


Thank you for your answer.

It was not really what I was looking for but finaly i found a solution : I use pydeck map which give me the option to use 1 dataframe for the inital view of the map and another dataframe for the scatterplot point

Thank you again for your help :smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.