Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
14.23k stars 1.7k forks source link

Page builder not writing results to output dataNode #371

Closed Forchapeatl closed 11 months ago

Forchapeatl commented 11 months ago

Description of the problem

Hello every one , Gui with page builder is unable to read changes on the input data node, hence passes stactic values to the build_message() function, and writes no result to the output data node

import taipy as tp
import taipy.gui.builder as tgb
from taipy import Gui, Config, Core

input_name = "Taipy"
message = None

with tgb.Page() as page:
    tgb.input(input_name)
    tgb.text(message)
    tgb.button("submit" , on_action='submit_scenario')

def submit_scenario(state):
    state.scenario.input_name.write(state.input_name)
    state.scenario.submit(wait=True)
    state.message = scenario.message.read()

def build_message(name: str):
    print(name)
    return f"Hello {name}!"

input_name_data_node_cfg = Config.configure_data_node(id="input_name")
message_data_node_cfg = Config.configure_data_node(id="message")
build_msg_task_cfg = Config.configure_task("build_msg", build_message, input_name_data_node_cfg, message_data_node_cfg)
scenario_cfg = Config.configure_scenario("scenario", task_configs=[build_msg_task_cfg])

if __name__ == "__main__":
    Core().run()
    scenario = tp.create_scenario(scenario_cfg)
    Gui(page).run()

https://github.com/Avaiga/taipy/assets/24577149/21b1043c-c1a8-4da5-9984-24ded7d26a3a

Expected behaviour

This code generates page with markup

import taipy as tp
import taipy.gui.builder as tgb
from taipy import Gui, Config, Core

page = """
<|{input_name}|input|>
<|submit|button|on_action=submit_scenario|>

<|{message}|text|>
"""

input_name = "Taipy"
message = None

def submit_scenario(state):
    state.scenario.input_name.write(state.input_name)
    state.scenario.submit(wait=True)
    state.message = scenario.message.read()

def build_message(name: str):
    print(name)
    return f"Hello {name}!"

input_name_data_node_cfg = Config.configure_data_node(id="input_name")
message_data_node_cfg = Config.configure_data_node(id="message")
build_msg_task_cfg = Config.configure_task("build_msg", build_message, input_name_data_node_cfg, message_data_node_cfg)
scenario_cfg = Config.configure_scenario("scenario", task_configs=[build_msg_task_cfg])

if __name__ == "__main__":
    Core().run()
    scenario = tp.create_scenario(scenario_cfg)
    Gui(page).run()

https://github.com/Avaiga/taipy/assets/24577149/ef734457-6c2f-4b05-86ed-4fcc0a5e42cf

FlorianJacta commented 11 months ago

The correct syntax for the page builder is this one:

import taipy as tp
import taipy.gui.builder as tgb
from taipy import Gui, Config, Core

input_name = "Taipy"
message = None

with tgb.Page() as page:
    tgb.input("{input_name}")
    tgb.text("{message}")
    tgb.button("submit" , on_action='submit_scenario')

def submit_scenario(state):
    state.scenario.input_name.write(state.input_name)
    state.scenario.submit(wait=True)
    state.message = scenario.message.read()

def build_message(name: str):
    print(name)
    return f"Hello {name}!"

input_name_data_node_cfg = Config.configure_data_node(id="input_name")
message_data_node_cfg = Config.configure_data_node(id="message")
build_msg_task_cfg = Config.configure_task("build_msg", build_message, input_name_data_node_cfg, message_data_node_cfg)
scenario_cfg = Config.configure_scenario("scenario", task_configs=[build_msg_task_cfg])

if __name__ == "__main__":
    Core().run()
    scenario = tp.create_scenario(scenario_cfg)
    Gui(page).run()

This should work properly. You still need the "and the { for the binding of Taipy variables.

Forchapeatl commented 11 months ago

Than you. It worked