Interact with component from outside #531
Answered
by
Hammer2900
Hammer2900
asked this question in
Question
-
Can you tell me if it's possible to interact with the component from outside. For example, send a command to change a count variable. Here is a simple example. import time
import idom
import ray
count, set_count = 0, 0
@idom.component
def ClickCount():
global count, set_count
count, set_count = idom.hooks.use_state(0)
return idom.html.button(
{'onClick': lambda event: set_count(count + 1)},
[f'Click count: {count}'],
)
@ray.remote
class ServerRun(object):
def __init__(self):
global count, set_count
while True:
count = count + 1
time.sleep(1)
if __name__ == '__main__':
ray.init(num_cpus=2)
db = ServerRun.options(name='dev').remote()
idom.run(ClickCount, port=8002) If it could be done, then you could write real-time applications. |
Beta Was this translation helpful? Give feedback.
Answered by
Hammer2900
Nov 15, 2021
Replies: 1 comment 6 replies
-
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I have understood correctly, this is the right way to interact.