Question: Can you add the callback and display _ map for the geolocation chart in the code below as well?: # Setup the Jupyter version of
Can you add the callback and displaymap for the geolocation chart in the code below as well?:
# Setup the Jupyter version of Dash
from jupyterdash import JupyterDash
# Configure the necessary Python module imports
import dashleaflet as dl
from dash import dcc
from dash import html
import plotly.express as px
from dash import dashtable
from dash.dependencies import Input, Output
# Configure the plotting routines
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#### FIX ME #####
# change animalshelter and AnimalShelter to match your CRUD Python module file name and class name
from animalshelter import AnimalShelter
###########################
# Data Manipulation Model
###########################
# FIX ME update with your username and password and CRUD Python module name. NOTE: You will
# likely need more variables for your constructor to handle the hostname and port of the MongoDB
# server, and the database and collection names
username "aacuser"
password "Justice
shelter AnimalShelterusername password
# class read method must support return of list object and accept projection json input
# sending the read method an empty document requests all documents be returned
df pdDataFrame.fromrecordsshelterreadall
printdf
# MongoDB v is going to return the id column and that is going to have an
# invlaid object type of 'ObjectID' which will cause the datatable to crash so we remove
# it in the dataframe here. The dfdrop command allows us to drop the column. If we do not set
# inplaceTrue it will reeturn a new dataframe that does not contain the dropped columns
dfdropcolumnsidinplaceTrue
## Debug
printlendftodictorient'records'
printdfcolumns
#########################
# Dashboard Layout View
#########################
app JupyterDashname
app.layout htmlDiv
htmlDivid'hiddendiv', styledisplay:'none'
htmlCenterhtmlBhtmlHSNHU CS Dashboard'
htmlHr
dashtable.DataTable
id'datatableid
columns
name: iid: i "deletable": False, "selectable": True for i in dfcolumns
datadftodictrecords
#Features of the datatable
pagesize # Limits the number of rows displayed per page
sortaction'native', # adds the ability to sort by column
filteraction'native', # adds the ability to filter by column
rowselectable "single", # adds the ability to select single rows
pageaction'native',
styletableheight: px 'overflowY': 'auto'
htmlBr
htmlHr
htmlDiv
id'mapid
className'col s m
#############################################
# Interaction Between Components Controller
#############################################
#This callback will highlight a row on the data table when the user selects it
@app.callback
Outputdatatableid 'styledataconditional'
Inputdatatableid 'selectedcolumns'
def updatestylesselectedcolumns:
return
if: 'columnid: i
'backgroundcolor': #DFFF
for i in selectedcolumns
# This callback will update the geolocation chart for the selected data entry
# derivedvirtualdata will be the set of data available from the datatable in the form of
# a dictionary.
# derivedvirtualselectedrows will be the selected rows in the table in the form of
# a list. For this application, we are only permitting single row selection so there is only
# one value in the list.
# The iloc method allows for a row, column notation to pull data from the datatable
@app.callback
Outputmapid "children"
Inputdatatableid "derivedvirtualdata"
Inputdatatableid "derivedvirtualselectedrows"
def updatemapviewData index:
dff pdDataFrame.fromdictviewData
# Because we only allow single row selection, the list can
# be converted to a row index here
if index is None:
row
else:
row index
# Austin TX is at
return
dlMapstylewidth: px 'height': px
center zoom children
dlTileLayerid"baselayerid
# Marker with tool tip and popup
# Column and define the gridcoordinates for
# the map
# Column defines the breed for the animal
# Column defines the name of the animal
dlMarkerpositiondffilocrowdffilocrow
children
dlTooltipdffilocrow
dlPopup
htmlHAnimal Name"
htmlPdffilocrow
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
