Visual Elements not updating in real time with Taipy GUI

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

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.

from taipy.gui import Gui
import pandas as pd

a_list = [1,2,3]
data = pd.DataFrame({"x":[1,2,3], "y":[2,1,3]})


md = """
<|Update|button|on_action=update|>

# My list
<|{a_list}|>

# My data
<|{data}|table|width=fit-content|>
"""

def update(state):
    state.a_list.append(4)
    state.data["y"] = [10, 4, 3] 

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)。您的代码将如下所示:

from taipy.gui import Gui
import pandas as pd

a_list = [1,2,3]
data = pd.DataFrame({"x":[1,2,3], "y":[2,1,3]})

md = """
<|Update|button|on_action=update|>

# My list
<|{a_list}|>

# My data
<|{data}|table|width=fit-content|>
"""
    
def update(state):
    state.a_list += [4]
    temp = state.data
    temp["y"] = [10, 4, 3]
    state.data = temp

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:

from taipy.gui import Gui
import pandas as pd

a_list = [1,2,3]
data = pd.DataFrame({&quot;x&quot;:[1,2,3], &quot;y&quot;:[2,1,3]})


md = &quot;&quot;&quot;
&lt;|Update|button|on_action=update|&gt;

# My list
&lt;|{a_list}|&gt;

# My data
&lt;|{data}|table|width=fit-content|&gt;
&quot;&quot;&quot;

def update(state):
    state.a_list += [4]
    temp = state.data
    temp[&quot;y&quot;] = [10, 4, 3] 
    state.data = temp

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:

确定