I am trying to get values in certain format using hovertemplate
and hover_info
but exact values are not showing on hovering. The hover values are columns in dataframe.
Code:
@app.callback(
Output("id-graph1", "figure"),
[Input("demo-dropdown", "value"), Input("year_slider", "value")],
)
def update_map(drop_value, year_value):
# print(year_value)
df_sub = df_copy.loc[
(df_copy["year"] >= year_value[0]) & (df_copy["year"] <= year_value[1])
]
df_sub = df_sub.loc[df_sub["country_txt"] == drop_value]
# print(df_sub.head())
random.seed(1)
# print(df_sub.head())
# create graph
location = [
(
go.Scattermapbox(
lon=df_sub["longitude"],
lat=df_sub["latitude"],
mode="markers+text",
marker=dict(size=10, allowoverlap=False, opacity=0.7, color="crimson"),
hoverinfo="text",
hovertext="<br>".join(
[
"lat: %{lat}",
"long: %{lon}",
"casualities: %{casualities_median}",
"city: %{city}",
"attack happened in: %{year}",
]
),
)
)
]
# return graph
return {
"data": location,
"layout": go.Layout(
uirevision="foo",
hovermode="closest",
hoverdistance=2,
mapbox=dict(
accesstoken=mapbox_access_token,
style="light",
center=dict(
lat=random.choice(df_sub["latitude"].tolist()),
lon=random.choice(df_sub["longitude"].tolist()),
),
zoom=3,
),
),
}
This is how it looks on hovering: