Step by step description of what I am trying to achieve:
- Create textfields, dropdown menus and other widgets which will serve as input for the calculations
- Have a single "“Run” button. When pressed, all info from the widgets in step 1 is used to calculate some final result.
- The outcome of the “run” should then be presented to the user in the panel. Also, if the user changes the inputs, clicks again on “Run”, both outcomes should be visible at the same time such that they can be compared. One possibility could, for example, be creating a new tab in the Tabs widgets for every to show the outcome of every run.
As an example, consider the code below:
import pandas as pd
import numpy as np
import panel as pn
pn.extension()
df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
text = pn.widgets.TextInput(placeholder='Enter column names here...')
dropdown1 = pn.widgets.Select(options=['Simple', 'Logorithmic', 'Quadratic'])
dropdown2 = pn.widgets.Select(options=['All', 'Only positive', 'Only negative'])
button = pn.widgets.Button(name='Run')
def run():
if dropdown1.value == "Simple":
if dropdown2 == "All":
df.loc[text.value]
elif dropdown2 == "Only positive":
pass
elif dropdown2 == "Only negative":
pass
elif dropdown1.value == "Logarithmic":
if dropdown2 == "All":
pass
elif dropdown2 == "Only positive":
pass
elif dropdown2 == "Only negative":
pass
elif dropdown1.value == "Quadratic":
if dropdown2 == "All":
pass
elif dropdown2 == "Only positive":
pass
elif dropdown2 == "Only negative":
pass
button.on_click(run)
panel = pn.WidgetBox(pn.Column(
text,
dropdown1,
dropdown2,
button
))
pn.serve(panel)