jchoo commited on
Commit
c2082cd
·
verified ·
1 Parent(s): 8879826

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -77
app.py CHANGED
@@ -759,61 +759,72 @@ options = ['Altruism', 'Fairness', 'spite', 'trust', 'reciprocity', 'free-riding
759
  select_widget = pn.widgets.Select(options=options, name='Select a category')
760
 
761
 
762
- # Define function to update chart
763
- def update_chart(value):
764
- if value:
765
- index = int(value.split()[-1]) - 1
766
- return charts[index]
767
- else:
768
- return None
769
-
770
- # Combine dropdown and chart
771
- @pn.depends(select1.param.value, select2.param.value)
772
- def update_plots(value1, value2):
773
- selected_chart1 = update_chart(value1)
774
- selected_chart2 = update_chart(value2)
775
- if selected_chart1 and selected_chart2:
776
- return pn.Row(selected_chart1, selected_chart2)
777
- elif selected_chart1:
778
- return selected_chart1
779
- elif selected_chart2:
780
- return selected_chart2
781
- else:
782
- return None
783
 
784
- # Define functions for each category
785
- def update_plots_altruism():
786
- return pn.Row(final, final5)
 
 
 
787
 
788
- def update_plots_fairness():
789
- return pn.Row(final2, final5)
790
 
791
- def update_plots_spite():
792
- return final
793
 
794
- def update_plots_trust():
795
- return final4
796
 
797
- def update_plots_reciprocity():
798
- return final5
799
 
800
- def update_plots_freeriding():
801
- return final6
802
 
803
- def update_plots_cooperation():
804
- return final6
 
 
 
 
 
 
 
 
805
 
806
- # Define a dictionary to map categories to update functions
807
- update_functions = {
808
- 'Altruism': update_plots_altruism,
809
- 'Fairness': update_plots_fairness,
810
- 'spite': update_plots_spite,
811
- 'trust': update_plots_trust,
812
- 'reciprocity': update_plots_reciprocity,
813
- 'freeriding': update_plots_freeriding,
814
- 'cooperation': update_plots_cooperation
815
- }
816
 
 
 
 
 
 
 
 
 
 
 
817
 
818
  # # Define function to update chart based on selected category
819
  # def update_plots_category(event):
@@ -825,44 +836,35 @@ update_functions = {
825
  # maincol.append(update_function())
826
  # else:
827
  # maincol.append(pn.pane.Markdown(f"No update function found for category: {selected_category}"))
828
-
829
- # Define function to update chart based on selected category
830
- def update_plots_category(event):
831
- selected_category = event.new
832
- maincol.clear() # Clear existing content in main column
833
-
834
- if selected_category in update_functions:
835
- update_function = update_functions[selected_category]
836
- maincol.append(update_function())
837
- else:
838
- maincol.append(pn.pane.Markdown(f"No update function found for category: {selected_category}"))
839
 
840
- # Append select_widget again to allow changing the category selection
841
- maincol.append(select_widget)
842
 
843
 
844
- # Callback function to handle select widget events
845
- def select_callback(event):
846
- selected_value = event.new
847
- maincol.clear() # Clear existing content in main column
848
 
849
- if selected_value == 'Choose Your Own':
850
- maincol.append(select1)
851
- maincol.append(select2)
852
- maincol.append(update_plots)
853
-
854
- elif selected_value == 'Based On Category':
855
- maincol.append(select_widget)
856
- select_widget.param.watch(update_plots_category, 'value')
857
 
858
- # # Bind the update_plots_category function to the select widget's 'value' parameter
859
- # select.param.watch
860
- # maincol.append(update_plots_category())
 
 
 
861
 
862
- # Bind the callback function to the select widget's 'value' parameter
863
- select0.param.watch(select_callback, 'value')
864
 
865
- maincol.append(select0)
866
 
867
  template.main.append(maincol)
868
  template.servable(title='SI649 Project2')
 
759
  select_widget = pn.widgets.Select(options=options, name='Select a category')
760
 
761
 
762
+ # # Define function to update chart
763
+ # def update_chart(value):
764
+ # if value:
765
+ # index = int(value.split()[-1]) - 1
766
+ # return charts[index]
767
+ # else:
768
+ # return None
769
+
770
+ # # Combine dropdown and chart
771
+ # @pn.depends(select1.param.value, select2.param.value)
772
+ # def update_plots(value1, value2):
773
+ # selected_chart1 = update_chart(value1)
774
+ # selected_chart2 = update_chart(value2)
775
+ # if selected_chart1 and selected_chart2:
776
+ # return pn.Row(selected_chart1, selected_chart2)
777
+ # elif selected_chart1:
778
+ # return selected_chart1
779
+ # elif selected_chart2:
780
+ # return selected_chart2
781
+ # else:
782
+ # return None
783
 
784
+ # # Define functions for each category
785
+ # def update_plots_altruism():
786
+ # return pn.Row(final, final5)
787
+
788
+ # def update_plots_fairness():
789
+ # return pn.Row(final2, final5)
790
 
791
+ # def update_plots_spite():
792
+ # return final
793
 
794
+ # def update_plots_trust():
795
+ # return final4
796
 
797
+ # def update_plots_reciprocity():
798
+ # return final5
799
 
800
+ # def update_plots_freeriding():
801
+ # return final6
802
 
803
+ # def update_plots_cooperation():
804
+ # return final6
805
 
806
+ # # Define a dictionary to map categories to update functions
807
+ # update_functions = {
808
+ # 'Altruism': update_plots_altruism,
809
+ # 'Fairness': update_plots_fairness,
810
+ # 'spite': update_plots_spite,
811
+ # 'trust': update_plots_trust,
812
+ # 'reciprocity': update_plots_reciprocity,
813
+ # 'freeriding': update_plots_freeriding,
814
+ # 'cooperation': update_plots_cooperation
815
+ # }
816
 
 
 
 
 
 
 
 
 
 
 
817
 
818
+ # # # Define function to update chart based on selected category
819
+ # # def update_plots_category(event):
820
+ # # selected_category = event.new
821
+ # # maincol.clear() # Clear existing content in main column
822
+
823
+ # # if selected_category in update_functions:
824
+ # # update_function = update_functions[selected_category]
825
+ # # maincol.append(update_function())
826
+ # # else:
827
+ # # maincol.append(pn.pane.Markdown(f"No update function found for category: {selected_category}"))
828
 
829
  # # Define function to update chart based on selected category
830
  # def update_plots_category(event):
 
836
  # maincol.append(update_function())
837
  # else:
838
  # maincol.append(pn.pane.Markdown(f"No update function found for category: {selected_category}"))
 
 
 
 
 
 
 
 
 
 
 
839
 
840
+ # # Append select_widget again to allow changing the category selection
841
+ # maincol.append(select_widget)
842
 
843
 
844
+ # # Callback function to handle select widget events
845
+ # def select_callback(event):
846
+ # selected_value = event.new
847
+ # maincol.clear() # Clear existing content in main column
848
 
849
+ # if selected_value == 'Choose Your Own':
850
+ # maincol.append(select1)
851
+ # maincol.append(select2)
852
+ # maincol.append(update_plots)
853
+
854
+ # elif selected_value == 'Based On Category':
855
+ # maincol.append(select_widget)
856
+ # select_widget.param.watch(update_plots_category, 'value')
857
 
858
+ # # # Bind the update_plots_category function to the select widget's 'value' parameter
859
+ # # select.param.watch
860
+ # # maincol.append(update_plots_category())
861
+
862
+ # # Bind the callback function to the select widget's 'value' parameter
863
+ # select0.param.watch(select_callback, 'value')
864
 
865
+ # maincol.append(select0)
 
866
 
867
+ maincol.append(select1)
868
 
869
  template.main.append(maincol)
870
  template.servable(title='SI649 Project2')