Skip to content
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

Return functions to dynamically update #132

Closed
ldr426 opened this issue Jul 27, 2023 · 1 comment
Closed

Return functions to dynamically update #132

ldr426 opened this issue Jul 27, 2023 · 1 comment

Comments

@ldr426
Copy link
Collaborator

ldr426 commented Jul 27, 2023

It turned out the proposed approach would not work to dynamically update the widgets after that, one need to proceed as follows if they want to both to set parameters and dynamically link widgets after that:

# we do not assign this to an object 
# this sets the channel in the Echoshader object
ds.eshader.echogram(channel=["38kHz"])
ds.eshader.Sv_range_slider(["38kHz"])
# pass the functions to panel: this allows for dynamic updates
panel.row(ds.eshader.echogram, ds.eshader.Sv_range_slider)

If we just run as discussed

echogram_widget = ds.eshader.echogram(channel=["38kHz"])
Sv_range_slider_widget = ds.eshader.Sv_range_slider(["38kHz"])
# pass the functions to panel: this allows for dynamic updates
panel.row(echogram_widget, Sv_range_slider_widget)

one would not be able to update the plots dynamically, as the widgets are static objects.

With the first scenario, we worry that even if we write in the documentation that they should pass the function, they will set the function call to an object and will pass it to panel and will be puzzled why it is not updating.

An alternative to mitigate this problem is to actually make echogram return a function instead of the holoviews object. To the user that might be a bit invisible.

# echogram_widget is a function
echogram_widget = ds.eshader.echogram(channel=["38kHz"])

# the function then can be passed to panel
panel.row(echogram_widget)

panel will accept the function and the echogram will plot.

The function can be created by some pseudo code like that

def echogram(MVBS_ds, ch, cmap):
    return(hv.Image(MVBS_ds, ch, map))

channel_select = panel.select()
cmap_input = panel.Input()

echogram_bind  = panel.bind(echogram, ch=channel_select, cmap=cmap_select)

def eg(MVBS_Sv, ch, cmap, echogram_bind):
    ch_sel.value = ch
    cmap_sel.value = cmap
    return (echogram_bind)

Of course, if the user just runs echogram_widget in a cell it will show that this is a function. To display the plot, one needs to run echogram_widget().

Yet another alternative is that they always create a changing widget if they want to change a value of the parameters, but this will result in too many widgets that we may not want to update.

Originally posted by @valentina-s in #107 (comment)

@valentina-s valentina-s changed the title Returen functions to dynamically update Return functions to dynamically update Aug 4, 2023
@valentina-s
Copy link
Contributor

Being addressed by #131.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants