figoyouwei / taipy_success

This is a sample code that tests the deployment on heroku
2 stars 2 forks source link

table add_row error #7

Closed figoyouwei closed 2 weeks ago

figoyouwei commented 3 weeks ago

Hi,

I added an add_row method in this .py https://github.com/figoyouwei/taipy_success/blob/main/apps/yfin/pages/yfin.py

The GUI shows the add button, but when clicked on, it returns: WARNING:root: --- 1 warning(s) were found for page 'yfinance' in variable 'gui_core_sc_error' ---

taipy_success/.venv/lib/python3.12/site-packages/taipy/gui/gui.py:1392: TaipyGuiWarning: on_action(): 'add_row' is not a valid function. _warn(f"on_action(): '{action}' is not a valid function.")

FlorianJacta commented 3 weeks ago

This means there is an issue with your function. Can you add debug=True in your run?

<Your Gui>.run(..., debug=True)

This way, the error message will show you more information. Then, you can send me the error message and we will look at it together!

figoyouwei commented 3 weeks ago

Yes, debug=True in the code, and that was all the message I got. Please run the code and fix it?

FlorianJacta commented 3 weeks ago

Please add more details to your issue. I don't know what code I should run. This code cannot be run by itself: https://github.com/figoyouwei/taipy_success/blob/main/apps/yfin/pages/yfin.py

Where do you use it? Where do you start your Gui with this page? What steps do you take to have this issue? Do you have any other logs associated?

figoyouwei commented 3 weeks ago

It is under the app called yfin https://github.com/figoyouwei/taipy_success/blob/main/apps/yfin

And there is the main.py to run the GUI and you will see this table.

Screenshot 2024-08-27 at 15 22 46
FlorianJacta commented 3 weeks ago

You are creating defining your page in the script where add_row is and add_row is also not imported in your main.py.

I would suggest keeping the normal way of creating the pages. yfin.py

"""
@author: Youwei Zheng
@target: yfinance table page
@update: 2024.08.26
"""

from taipy.gui import notify
import taipy.gui.builder as tgb
import pandas as pd

# ------------------------------
# on_add
# ------------------------------

def add_row(state):
    empty_row = pd.DataFrame(
        [[None for _ in state.df_pcs.columns]], columns=state.df_pcs.columns
    )
    state.data_df = pd.concat([empty_row, state.df_pcs], axis=0, ignore_index=True)

    notify(state, "S", f"Added one row")

# ------------------------------
# Create page
# ------------------------------

with tgb.Page() as page_yfin:
    # Create title
    tgb.toggle(theme=True)
    tgb.text("# Table Data from yfinance ", mode="md", class_name="text-center pb1")

    # Create table
    tgb.table(
        "{data_df}", editable=True, on_add=add_row, on_edit=False, on_delete=False
    )

main.py

"""
@author: Youwei Zheng
@target: Main app
@update: 2024.08.13
"""

from datetime import datetime

from taipy.gui import Gui

import pages.calculator as page_calculator
import pages.chatbot as page_chatbot
from pages.yfin import page_yfin, add_row

from turing import compute_points
from models.calculator import Level, Point

from tools import download_yfin, process_yfin

if __name__ == "__main__":

    # Create yfinance page
    current_date = datetime.now().strftime("%Y-%m-%d")
    args_in = (
        "^SPX",
        "1d",
        "2024-08-01",
        current_date,
    )
    df = download_yfin(args_in)
    df_pcs = process_yfin(df)
    # data_df is used for your table; this is your bound variable
    # it is defined in the main.py so this variable is a global variable
    # you could or should define it in yfin.py
    data_df = df_pcs

    # Create calcuator page
    page_calculator = page_calculator.create_page()

    # Create data instances of calculator model
    levels = Level()
    points = Point()
    points = compute_points(levels)

    # Create calcuator page
    page_chatbot = page_chatbot.create_page()

    pages = {
        "/": "<center><|navbar|></center>",
        "yfinance": page_yfin,
        "calculator": page_calculator,
        "chatbot": page_chatbot,
    }

    # Run page
    Gui(pages=pages).run(
        title="Taipy Success",
        debug=True,
        use_reloader=True,
        watermark="Made by CR7",
        margin="4em",
        host="0.0.0.0",
        port=9000,
        # base_url="/shggzyapp/" # key to nginx
    )
figoyouwei commented 3 weeks ago

ok, I think I see your point with the "you could or should define it in yfin.py".

The code is ok with add_row, I will play around with the edit and delete and comment back.

FlorianJacta commented 3 weeks ago

Great!

figoyouwei commented 2 weeks ago

edit and delete both work.

FlorianJacta commented 2 weeks ago

Great news!