Coder Social home page Coder Social logo

Comments (3)

philippjfr avatar philippjfr commented on June 20, 2024

This already exists and has to be documented, specifically it's rx_run.rx.updating()

from param.

MarcSkovMadsen avatar MarcSkovMadsen commented on June 20, 2024

How would I combine .rx.updating() with .watch. I can't figure out how as .watch(...) just returns None. I.e. I don't get a handle on anything I can do .rx.updating() on.

import panel as pn
from time import sleep
pn.extension()

submit = pn.widgets.Button(name="Start the wind turbine")

def run(clicked):
    sleep(0.5)
    print("done")

rx_run = pn.rx(submit).rx.watch(run)
submit.loading=submit.disabled=rx_run.rx.running()

# Figure out how to watch

pn.Column(submit).servable()

image

UPDATE

After some experimentation I found I need to break it down into 3 seperate steps.

import panel as pn
from time import sleep
pn.extension()

def run(clicked):
    sleep(0.5)
    print("done")

submit = pn.widgets.Button(name="Start the wind turbine", )

rx_run = pn.rx(submit)
submit.loading=submit.disabled=rx_run.rx.updating()
rx_run.rx.watch(run)

pn.Column(submit).servable()

Hmmm. My thinking was that I would like to disable the Button while the run function is running. Instead I can disable it while its clicked.

from param.

MarcSkovMadsen avatar MarcSkovMadsen commented on June 20, 2024

At the same time I am think whether the .rx .watch api is what you would expect. Why do you have to specify a function as argument? Why can't you just watch and execute the pipeline as in the below?

import panel as pn
from time import sleep
pn.extension()

is_active = pn.rx(False)

submit = pn.widgets.Button(name="Start the wind turbine", loading=is_active, disabled=is_active)

def run(clicked):
    is_active.rx.value = True
    sleep(0.5)
    print("done")
    is_active.rx.value = False

rx_run = pn.rx(run)(submit).rx.watch()

# Figure out how to watch

pn.Column(submit).servable()

image

from param.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.