OSOceanAcoustics / echoshader

Interactive visualization of ocean sonar data
https://echoshader.readthedocs.io
MIT License
9 stars 8 forks source link

Return functions to dynamically update #132

Closed ldr426 closed 11 months ago

ldr426 commented 11 months ago

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 https://github.com/OSOceanAcoustics/echoshader/issues/107#issuecomment-1652728562

valentina-s commented 11 months ago

Being addressed by #131.