0

I am working on a passenger forecast system and got introduced to hvplots and widgets. The idea is have a panel to select a day of the week and a slider showing time_frame in which data is taken in, every 5 mins, 10 mins etc. Typically, when using the typical console, by simply asking for the user input for the day and split of time, the code works fine and gives the desired graph and table using matlibplot. However, when using hvplots and widgets, when I select a value in the interactive panel, the default value stays and doesn't change the graph/table after changing the panel. Though both day of the week and time_frame are used throughout the code in various assignments and loops. Unfortunately, I cannot provide with the dataset, but I can provide with the code.Below is a small part of the code, not fully but just to give an idea:

X = pn.widgets.IntSlider(name='Time Divison (mins)', start=5, end=20, step=5)
Dweek = pn.widgets.Select(name='DayChosen', options=['Monday', 'Tuesday', 
                                                     'Wedesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) 

#interact(f, options=['Monday', 'Tuesday', 'Wedesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] )

#Dweek = input("Enter a day of the week: ")
#X = input("How many minutes would you like to split the graph")
#X = int(X)
dDay = data['DateofFlight'].dt.day_name()


dScannedDateTime = data.set_index(dDay).loc[Dweek.value]['ScanDateTime']
dScannedTime = data.set_index(dDay).loc[Dweek.value]['ScanTime']
dTimeHour = dScannedDateTime.dt.hour
dTimeMinute = dScannedDateTime.dt.minute


dw = data.set_index(dDay).loc[Dweek.value]['FlightNumber'].unique()
dl = data.set_index(dDay).loc[Dweek.value]['FlightNumber']
dRec = data.set_index(dDay).loc[Dweek.value]['RecID']
dCode = data.set_index(dDay).loc[Dweek.value]['AirlineName']
dDepTime = data.set_index(dDay).loc[Dweek.value]['ScheduleTime']
dFlightNum = data['FlightNumber']
Michael S.
  • 3,050
  • 4
  • 19
  • 34

1 Answers1

0

It is a bit difficult to reply as the code is quite incomplete. There are at least two ways to approach this problem.

First using Panel widgets and hvPlot's interactive feature. The interactive feature allows you to turn your data pipeline, i.e. a sequence of methods you apply to a Pandas/Xarray object, into an interactive one by replacing the parameters in your pipeline by widgets. The pipeline output displayed along with the widgets, changing a widget value re-executes the pipeline and you see the output changing.

Second using Panel only, by declaring widgets and by using either pn.interact or pn.bind to create a function that will be re-executed whenever a widget value changes.

MaximeL
  • 391
  • 3
  • 7