jchoo commited on
Commit
da67287
·
verified ·
1 Parent(s): 2a25103

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +122 -102
app.py CHANGED
@@ -700,101 +700,132 @@ final6 = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
700
  #Final_Final
701
  final_final = (final | final2 | final3 ) & (final4 | final5 | final6)
702
 
703
- #Dashboard
704
- import panel as pn
705
- import vega_datasets
706
 
707
- # Enable Panel extensions
708
  pn.extension(design='bootstrap')
 
 
709
  pn.extension('vega')
710
 
 
711
  template = pn.template.BootstrapTemplate(
712
- title='SI649 Project2',
713
  )
714
 
715
- # the main column will hold our key content
716
  maincol = pn.Column()
 
717
 
718
- options1 = ['ALL', 'Choose Your Own', 'Based On Category']
719
- select0 = pn.widgets.Select(options=options1, name='Choose what to compare')
720
- # maincol.append(select0)
721
 
722
- # Charts
723
- charts = []
724
- charts.append(final)
725
- charts.append(final2)
726
- charts.append(final3)
727
- charts.append(final4)
728
- charts.append(final5)
729
- charts.append(final6)
730
 
731
- # Define options for dropdown
732
- options = [f'Chart {i+1}' for i in range(len(charts))]
733
 
734
- # Panel widgets
735
- select1 = pn.widgets.Select(options=options, name='Select Chart 1')
736
- select2 = pn.widgets.Select(options=options, name='Select Chart 2')
737
 
738
- options = ['Altruism', 'Fairness', 'spite', 'trust', 'reciprocity', 'free-riding', 'cooperation']
739
- select_widget = pn.widgets.Select(options=options, name='Select a category')
 
740
 
 
 
 
741
 
742
- # Define function to update chart
743
- def update_chart(value):
744
- if value:
745
- index = int(value.split()[-1]) - 1
746
- return charts[index]
747
- else:
748
- return None
749
 
750
- # Combine dropdown and chart
751
- @pn.depends(select1.param.value, select2.param.value)
752
- def update_plots(value1, value2):
753
- selected_chart1 = update_chart(value1)
754
- selected_chart2 = update_chart(value2)
755
- if selected_chart1 and selected_chart2:
756
- return pn.Row(selected_chart1, selected_chart2)
757
- elif selected_chart1:
758
- return selected_chart1
759
- elif selected_chart2:
760
- return selected_chart2
761
- else:
762
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
763
 
764
- # Define functions for each category
765
- def update_plots_altruism():
766
- return pn.Row(final, final5)
767
 
768
- def update_plots_fairness():
769
- return pn.Row(final2, final5)
770
 
771
- def update_plots_spite():
772
- return final
773
 
774
- def update_plots_trust():
775
- return final4
776
 
777
- def update_plots_reciprocity():
778
- return final5
779
 
780
- def update_plots_freeriding():
781
- return final6
782
 
783
- def update_plots_cooperation():
784
- return final6
785
 
786
- # Define a dictionary to map categories to update functions
787
- update_functions = {
788
- 'Altruism': update_plots_altruism,
789
- 'Fairness': update_plots_fairness,
790
- 'spite': update_plots_spite,
791
- 'trust': update_plots_trust,
792
- 'reciprocity': update_plots_reciprocity,
793
- 'freeriding': update_plots_freeriding,
794
- 'cooperation': update_plots_cooperation
795
- }
796
 
797
 
 
 
 
 
 
 
 
 
 
 
 
798
  # # Define function to update chart based on selected category
799
  # def update_plots_category(event):
800
  # selected_category = event.new
@@ -805,44 +836,33 @@ update_functions = {
805
  # maincol.append(update_function())
806
  # else:
807
  # maincol.append(pn.pane.Markdown(f"No update function found for category: {selected_category}"))
808
-
809
- # Define function to update chart based on selected category
810
- def update_plots_category(event):
811
- selected_category = event.new
812
- maincol.clear() # Clear existing content in main column
813
-
814
- if selected_category in update_functions:
815
- update_function = update_functions[selected_category]
816
- maincol.append(update_function())
817
- else:
818
- maincol.append(pn.pane.Markdown(f"No update function found for category: {selected_category}"))
819
 
820
- # Append select_widget again to allow changing the category selection
821
- maincol.append(select_widget)
822
 
823
 
824
- # Callback function to handle select widget events
825
- def select_callback(event):
826
- selected_value = event.new
827
- maincol.clear() # Clear existing content in main column
828
 
829
- if selected_value == 'Choose Your Own':
830
- maincol.append(select1)
831
- maincol.append(select2)
832
- maincol.append(update_plots)
833
-
834
- elif selected_value == 'Based On Category':
835
- maincol.append(select_widget)
836
- select_widget.param.watch(update_plots_category, 'value')
837
 
838
- # # Bind the update_plots_category function to the select widget's 'value' parameter
839
- # select.param.watch
840
- # maincol.append(update_plots_category())
841
 
842
- # Bind the callback function to the select widget's 'value' parameter
843
- select0.param.watch(select_callback, 'value')
844
 
845
- maincol.append(select0)
846
 
847
- template.main.append(maincol)
848
- template.servable()
 
700
  #Final_Final
701
  final_final = (final | final2 | final3 ) & (final4 | final5 | final6)
702
 
 
 
 
703
 
704
+ # we want to use bootstrap/template, tell Panel to load up what we need
705
  pn.extension(design='bootstrap')
706
+
707
+ # we want to use vega, tell Panel to load up what we need
708
  pn.extension('vega')
709
 
710
+ # create a basic template using bootstrap
711
  template = pn.template.BootstrapTemplate(
712
+ title='SI649 project2test',
713
  )
714
 
 
715
  maincol = pn.Column()
716
+ maincol.append("TEST")
717
 
718
+ template.main.append(maincol)
 
 
719
 
720
+ template.servable(title="SI649 Project2Test")
 
 
 
 
 
 
 
721
 
 
 
722
 
723
+ # #Dashboard
724
+ # import panel as pn
725
+ # import vega_datasets
726
 
727
+ # # Enable Panel extensions
728
+ # pn.extension(design='bootstrap')
729
+ # pn.extension('vega')
730
 
731
+ # template = pn.template.BootstrapTemplate(
732
+ # title='SI649 Project2',
733
+ # )
734
 
735
+ # # the main column will hold our key content
736
+ # maincol = pn.Column()
 
 
 
 
 
737
 
738
+ # options1 = ['ALL', 'Choose Your Own', 'Based On Category']
739
+ # select0 = pn.widgets.Select(options=options1, name='Choose what to compare')
740
+ # # maincol.append(select0)
741
+
742
+ # # Charts
743
+ # charts = []
744
+ # charts.append(final)
745
+ # charts.append(final2)
746
+ # charts.append(final3)
747
+ # charts.append(final4)
748
+ # charts.append(final5)
749
+ # charts.append(final6)
750
+
751
+ # # Define options for dropdown
752
+ # options = [f'Chart {i+1}' for i in range(len(charts))]
753
+
754
+ # # Panel widgets
755
+ # select1 = pn.widgets.Select(options=options, name='Select Chart 1')
756
+ # select2 = pn.widgets.Select(options=options, name='Select Chart 2')
757
+
758
+ # options = ['Altruism', 'Fairness', 'spite', 'trust', 'reciprocity', 'free-riding', 'cooperation']
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):
831
  # selected_category = event.new
 
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()