How do I add loading indicator to a holoviz panel which is displayed while some computation is done?

320 views Asked by At

I am working on a project which uses the holoviz panel for display. The panel has a button which does some heavy computation on click and displays result after a few seconds. How do I modify the code such that I get a loading indicator(spinner) while data is being fetched? I probably need to add loading_indicator = True somewhere(pass as parameter), but haven't had any success so far. Is there an alternate way? Minimal code:

import panel as pn
import pandas as pd

pn.extension()

submit_button = pn.widgets.Button(name='Submit', button_type='primary', width = 180)
radio_buttons_group = pn.widgets.RadioButtonGroup(options=['Ying', 'Yang'], button_type='default')
outer_col = pn.Column(radio_buttons_group, submit_button)

@pn.depends(submit_button.param.clicks, watch=True)
def display_result(event):
    if(len(outer_col) > 2):
        outer_col.pop(len(outer_col)-1)

    if(radio_buttons_group.value == 'Ying'):
        ying_view()
    else:
        yang_view()
        
def ying_view():
    #some heavy computation
    outer_col.append(pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})) #sample
    
def yang_view():
    #some heavy computation
    outer_col.append(pd.DataFrame({'col1': [5, 6], 'col2': [7, 8]})) #sample
    
outer_col                                                            #displays the result
0

There are 0 answers