NimaKL commited on
Commit
05415ea
1 Parent(s): db06b3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -13
app.py CHANGED
@@ -70,19 +70,60 @@ if text:
70
  #st.markdown("<br>", unsafe_allow_html=True)
71
  st.success(result)
72
 
73
- import matplotlib.pyplot as plt
74
-
75
- # Pie chart, where the slices will be ordered and plotted counter-clockwise:
76
- labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
77
- sizes = [15, 30, 45, 10]
78
- explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
79
-
80
- fig1, ax1 = plt.subplots()
81
- ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
82
- shadow=True, startangle=90)
83
- ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
84
-
85
- st.pyplot(fig1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  # description = '<table style="border: collapse; padding-top: 1px;"><tr><div style="height: 62px;"></div></tr><tr><p style="border-width: medium; border-color: #aa5e70; border-radius: 10px;padding-top: 1px;padding-left: 20px;background:#20212a;font-family:Courier New; color: white;font-size: 36px; font-weight: boldest;">'+result+'</p></tr><table>'
87
  # st.markdown(description, unsafe_allow_html=True)
88
 
 
70
  #st.markdown("<br>", unsafe_allow_html=True)
71
  st.success(result)
72
 
73
+ st.markdown(''' <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
74
+ <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.2.js"></script>
75
+ <div style="width: 500px; height: 500px">
76
+ <canvas id="myChart"></canvas>
77
+ </div>
78
+ <script type="text/javascript">
79
+ var data = {
80
+ datasets: [{
81
+ data: [.88, .1, .02, .01, .002],
82
+ backgroundColor: [
83
+ "#F7464A",
84
+ "#46BFBD",
85
+ "#FDB45C",
86
+ "#555555",
87
+ "#CCCCCC"
88
+ ]
89
+ }],
90
+ labels: [
91
+ "Red",
92
+ "Green",
93
+ "Yellow",
94
+ "WHAT",
95
+ "YOOOO"
96
+ ]
97
+ };
98
+
99
+ $(document).ready(
100
+ function() {
101
+ var canvas = document.getElementById("myChart");
102
+ var ctx = canvas.getContext("2d");
103
+ var myNewChart = new Chart(ctx, {
104
+ type: 'pie',
105
+ data: data
106
+ });
107
+
108
+ canvas.onclick = function(evt) {
109
+ var activePoints = myNewChart.getElementsAtEvent(evt);
110
+ if (activePoints[0]) {
111
+ var chartData = activePoints[0]['_chart'].config.data;
112
+ var idx = activePoints[0]['_index'];
113
+
114
+ var label = chartData.labels[idx];
115
+ var value = chartData.datasets[0].data[idx];
116
+
117
+ var url = "http://example.com/?label=" + label + "&value=" + value;
118
+ console.log(url);
119
+ alert(url);
120
+ }
121
+ };
122
+ }
123
+ );
124
+
125
+ </script>
126
+ ''')
127
  # description = '<table style="border: collapse; padding-top: 1px;"><tr><div style="height: 62px;"></div></tr><tr><p style="border-width: medium; border-color: #aa5e70; border-radius: 10px;padding-top: 1px;padding-left: 20px;background:#20212a;font-family:Courier New; color: white;font-size: 36px; font-weight: boldest;">'+result+'</p></tr><table>'
128
  # st.markdown(description, unsafe_allow_html=True)
129