Search code examples
error-handlingundefinedtaipypython-simplenamespace

Issue using Taipy


I encoutered this bug using taipy. please kinldy help me out. this is a project I must submit by tomorrow. The problem is on the map.py page. I am using only 2 pages. app.py(home) and map.py. I have "traffic_category" defined but yet getting error

This is the error: --- 3 warning(s) were found for page 'maps' in variable 'page' ---

  • Warning 1: Variable 'traffic_category' is not available in either the 'main' or 'main' modules.
  • Warning 2: Variable 'traffic_category' is not defined (in expression '{traffic_category}'): 'types.SimpleNamespace' object has no attribute 'traffic_category'
  • Warning 3: Cannot evaluate expression 'traffic_category': name 'traffic_category' is not defined

This was the code in the map.py page

import collections
import gmaps
import pandas as pd
from taipy.gui import Markdown, notify
from custom_funcs.get_data_with_coordinates import get_location

data_map = pd.read_csv('files/final_data.csv', usecols=\["date", "content","traffic_class", "place"\]).dropna()

traffic_category = "free flow"
selectors = list(data_map.traffic_class.unique())

data = get_location(data_map, traffic_category).dropna()

def display_map(data):

    # Define the center of the map
    center = (data['lat'].mean(), data['lng'].mean())
    locations=data[['lat', 'lng']]
    
    # Define the figure layout
    fig_layout = {
        'width': '800px',
        'height': '600px',
        'border': '1px solid black',
        'padding': '10px'
    }
    
    # Create the map figure
    fig = gmaps.figure(
        center=center, 
        zoom_level=12, 
        layout=fig_layout,
        map_type='HYBRID',
    )
    
    fig.add_layer(gmaps.heatmap_layer(locations))
    
    
    # Display the map
    fig

def on_change(state, var, val):
 if var == "traffic_category":
 traffic_category = val
 notify(state, f"Viewing Map for {val}")
 state.data = get_location(data_map, val).dropna()
 display_map(data)

page="""

#####Check maps here

######Check the maps for the traffic Catogories in Lagos below
<|layout|columns=1 200px|
<|
<|{traffic_category}|selector|lov={selectors}|dropdown|label=See Map|>
|>

<|
<|{traffic_category}|>
|>

|>

"""

Solution

  • Import traffic_category into the Script file where the Gui.run() is executed.

    It seems like this variable is not accessible from where you call it. Importing this variable in the Script file where the Gui.run() is executed makes the variable, Global.