Visual Elements not updating in real time with Taipy GUI

huangapple go评论111阅读模式
英文:

Visual Elements not updating in real time with Taipy GUI

问题

对不起,我不会为您翻译代码。

英文:

Is it normal that when I attempt to add a value to my list or change my data using a button, I do not observe any modifications on the GUI?

Despite this, after refreshing the page, the accurate list is displayed.

  1. from taipy.gui import Gui
  2. import pandas as pd
  3. a_list = [1,2,3]
  4. data = pd.DataFrame({"x":[1,2,3], "y":[2,1,3]})
  5. md = """
  6. <|Update|button|on_action=update|>
  7. # My list
  8. <|{a_list}|>
  9. # My data
  10. <|{data}|table|width=fit-content|>
  11. """
  12. def update(state):
  13. state.a_list.append(4)
  14. state.data["y"] = [10, 4, 3]
  15. Gui(md).run()

For example, in the code above, clicking the button should add 4 to my list and change my table. However, I see no modification in real time. When I refresh my page, I see the right modifications.

After clicking and before refreshing:

<img src="https://i.stack.imgur.com/RkKko.png" width="300" height="300">

After refreshing:

<img src="https://i.stack.imgur.com/AZwtc.png" width="300" height="300">

答案1

得分: 1

Taipy在这一组特定赋值(.append().drop())中不直接更改您的GUI。要实时看到更改,您必须使用普通的“等于”赋值(state.xxx = yyy)。您的代码将如下所示:

  1. from taipy.gui import Gui
  2. import pandas as pd
  3. a_list = [1,2,3]
  4. data = pd.DataFrame({"x":[1,2,3], "y":[2,1,3]})
  5. md = """
  6. <|Update|button|on_action=update|>
  7. # My list
  8. <|{a_list}|>
  9. # My data
  10. <|{data}|table|width=fit-content|>
  11. """
  12. def update(state):
  13. state.a_list += [4]
  14. temp = state.data
  15. temp["y"] = [10, 4, 3]
  16. state.data = temp
  17. Gui(md).run()

请注意,这是一段Python代码示例,包括Taipy的GUI元素和一个用于更新GUI的函数。

英文:

Taipy does not directly change your GUI with this set of specific assignments (.append(), .drop()). You must use a regular ‘equals’ assignment to see changes in real time (state.xxx = yyy). Your code will look like this:

  1. from taipy.gui import Gui
  2. import pandas as pd
  3. a_list = [1,2,3]
  4. data = pd.DataFrame({&quot;x&quot;:[1,2,3], &quot;y&quot;:[2,1,3]})
  5. md = &quot;&quot;&quot;
  6. &lt;|Update|button|on_action=update|&gt;
  7. # My list
  8. &lt;|{a_list}|&gt;
  9. # My data
  10. &lt;|{data}|table|width=fit-content|&gt;
  11. &quot;&quot;&quot;
  12. def update(state):
  13. state.a_list += [4]
  14. temp = state.data
  15. temp[&quot;y&quot;] = [10, 4, 3]
  16. state.data = temp
  17. Gui(md).run()

huangapple
  • 本文由 发表于 2023年3月3日 23:13:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定