-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Long callbacks are unintuitive #888
Comments
It stops at 20, which is normal. Your interval is 500 so this function is called each 0.5 seconds and your heavy function takes 10 seconds.
You can extract it. Please take a look at the code below.
It will not break. There's a bug if you don't specify user_function_args. We should create an issue on this. We should create an issue on how to improve the doc and one on how to improve the ease of use of this feature. I would want to add on example like this. Tell me if this example help you: from taipy.gui import Gui, Markdown, invoke_long_callback, notify
import numpy as np
status = 0
num_iterations = 10_000_000
pi_list = []
def pi_approx(num_iterations):
k, s = 3.0, 1.0
pi_list = []
for i in range(num_iterations):
s = s-((1/k) * (-1)**i)
k += 2
if (i+1)%(int(num_iterations/1_000)+1) == 0:
pi_list += [np.abs(4*s-np.pi)]
return pi_list
def heavy_status(state, status, pi_list):
notify(state, 'i', f"Status parameter: {status}")
if isinstance(status, bool):
if status:
notify(state, 'success', "Finished")
state.pi_list = pi_list
else:
notify(state, 'error', f"An error was raised")
else:
state.status += 1
def on_action(state):
invoke_long_callback(state,
pi_approx, [int(state.num_iterations)],
heavy_status, [],
2000)
page = Markdown("""
How many times was the status function called? <|{status}|>
## Number of approximation
<|{num_iterations}|number|label=# of approximation|>
<|Approximate pie|button|on_action=on_action|>
## Evolution of approximation
<|{pi_list}|chart|layout={layout}|>
""")
layout = {
"yaxis": {
"type": 'log',
"autorange": True
}
}
Gui(page).run(port=1234, host="0.0.0.0") |
@FlorianJacta added a good code example to the doc on long callback: It might just be enough to fix this issue. |
The Tutorial has been changed to include an example. Remaining to do: Add a complete example downloadable from the user manual. |
TLDR
Long callbacks have a weird and buggy argument structure. The documentation does not provide working examples
Documentation
The documentation contains three pages about long callbacks:
All three pages ramble with only text and code. They do not provide a single working example that the user can try out and instead use:
This is so unclear that I read all three pages and could not do a long callback. I had to go through our demos to find out how to use a long callback and get the result.
Replacing all this text with a few working examples would go a long way:
Bugs
Even then, I still have a few questions:
The text was updated successfully, but these errors were encountered: