Question: I need help with an error message I keep getting, here is the code: # Setup the Jupyter version of Dash from jupyter _ dash
I need help with an error message I keep getting, here is the code:
# 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 "PASS
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.fromrecordsshelterread
# 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 JupyterDashSimpleExample
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
#FIXME: Set up the features for your interactive data table to make it userfriendly for your client
pagesize
paginationmodefe
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:
#FIXME Add in the code for your geolocation chart
dff pdDataFrame.fromdictviewData
# 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
dl
Markerpositiondffilocrowdffilocrow children
dlTooltipdffilocrow
dlPopup
htmlHAnimal Name"
htmlPdffilocrow
app.runserverdebugTrue
And the error I am getting says there is a problem with line which is :
dfdropcolumnsidinplaceTrue
At the bottom of the error message it says :
KeyError: id not found in axis"
Please help!
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
