@@ -62,7 +62,7 @@ def construct_tabs(tab_list):
6262questions = [map_qkey_to_question (key ) for key in questions_keys ]
6363#QUESTION_MAP = {question : i for i, question in enumerate(questions)}
6464FILTER_OPTIONS = open (join (pwd , 'dashboard/data/filters.txt' )).read ().split ('\n ' )
65- MARGINS = ( 10 , 10 , 10 , 10 )
65+ FILTER_OPTIONS_METHOD = open ( join ( pwd , 'dashboard/data/filters_methods.txt' )). read (). split ( ' \n ' )
6666
6767# Data displayed on startup:
6868START_DATA_BAR = map_qkey_to_question ("careerLevel" )
@@ -89,12 +89,12 @@ def construct_tabs(tab_list):
8989#### Control widgets
9090# Bar chart
9191# D: question select could also be a slider?
92- question_select = pn .widgets .Select (name = "Select a Question" , value = START_DATA_BAR ,
93- options = questions )#, description="Select the survey question, which results should be displayed.", margin=MARGINS )
92+ question_select = pn .widgets .Select (name = "Select a Question from the survey " , value = START_DATA_BAR ,
93+ options = questions )#, description="Select the survey question, which results should be displayed.")
9494
95- multi_choice = pn .widgets .MultiChoice (name = "Filter data by research field" , value = ["All" ], options = FILTER_OPTIONS )#,
96- #description="Select which data subset to be displayed.", margin=MARGINS )
97- multi_choice = pn .widgets .MultiChoice (name = "Filter data by research field " , value = ["All" ], options = FILTER_OPTIONS )
95+ multi_choice = pn .widgets .MultiChoice (name = "Filter by research field" , value = ["All" ], options = FILTER_OPTIONS )#,
96+ #description="Select which data subset to be displayed.")
97+ multi_choice_method = pn .widgets .MultiChoice (name = "Filter by data generation method " , value = ["All" ], options = FILTER_OPTIONS_METHOD )
9898
9999
100100# D: better than a Select would be to use the HMC template for this...
@@ -114,7 +114,6 @@ def construct_tabs(tab_list):
114114 options = FILTER_OPTIONS )
115115menu = ['Barchart' , 'Correlation Plot' ]#('Barchart', 'bar_chart'), ('Correlation Plot', '(corr_plot')]
116116button_bar = pn .widgets .Select (name = "Add a chart" , options = menu )
117- #button_corr = Button(label="Add correlation chart display", button_type="success")
118117
119118TOOLTIPS = [
120119 ("Title" , "@title" ),
@@ -136,12 +135,13 @@ def select_data():#question_select=question_select, multi_choice=multi_choice):
136135 #TODO, also some things are excluded
137136
138137 data_filters = multi_choice .value
139-
138+ data_filters_method = multi_choice_method . value
140139 # need something like [index: index_name, full question: '', title; '', 'key order' : [], 'skipped keys':[]]
141140
142141 # for now this is greedy, if to slow think of another way
143142 # we want to display anything in terms of researchArea, todo better was to d filter, generalize this
144143 df = filter_dataframe (survey_data , include = [q_index , "researchArea" ], exclude = [(q_index , to_exclude )])
144+ #df = filter_dataframe(df, include=[q_index, "researchArea"], exclude=[(q_index, to_exclude)])
145145 data_all = get_all_values (df , q_index )
146146
147147 exclude = []
@@ -184,9 +184,15 @@ def select_data_corr():#question_select2=question_select2, question_select3=ques
184184 x_range = HCS_orderedCats [q1_key ] #list(survey_data[q1_key].value_counts().keys())
185185 y_range = HCS_orderedCats [q2_key ] #list(survey_data[q2_key].value_counts().keys())
186186
187+
188+ data_filters = multi_choice .value
189+ data_filters_method = multi_choice_method .value
190+
187191 # If this is slow to calculate each time, it might make sense to calculate all of these
188192 # at start up. i.e n^2 tables
189- cross_tab = calculate_crosstab (survey_data , q1_key , q2_key )
193+ df = filter_dataframe (survey_data , include = [q1_key , q2_key , "researchArea" ], exclude = [])
194+
195+ cross_tab = calculate_crosstab (df , q1_key , q2_key )
190196 # marker size is radius, we want the Area to be proportional to the value
191197 # we also scale the markers with the max values are to small, or depending how many Cat, or
192198 # figure width...
@@ -204,43 +210,27 @@ def select_data_corr():#question_select2=question_select2, question_select3=ques
204210
205211 title = f'{ q1_key } in dependence to { q2_key } '
206212 # Bokeh plots need a ColumnDataSource, but this can be initialized from a pandas
207- #selected = ColumnDataSource(data=dict(x_values=cross_tab[q1_key], y_values=cross_tab[q2_key],
208- # markersize=cross_tab['percentage'], total=))
209-
210213 selected = ColumnDataSource (cross_tab )
211214
212215 display_options = {'x_range' : x_range , 'y_range' : y_range ,
213216 'tooltips' : tooltips , 'title' : title }
214217 return selected , display_options , marker_scale
215218
216219
217-
218- #def select_chart(chart_select=chart_select):
219- ## """Select how the data should be displayed"""
220- # chart_type = chart_select.value.strip()
221- # return chart_type
222-
223220def update (target , event , charttype = 1 ):
224- """Update the charts"""
221+ """Update the charts
222+
223+ The target will be replaced, the event contains what interaction was trickered.
224+ Here we assume value change, because no others where allowed.
225+ """
225226 print (event )
226- ob_index = 0
227227 df , ydata_spec , question = select_data ()
228- #charttype = select_chart(chart_select=chart_select)
229-
230- #source.data = dict(value=df.data['value'], counts=df.data['counts'], legend_labels=df.data['legend_labels'])
231228 source = df
232- # TODO: always plot piechart in seperate tab
233- #if charttype == 'pie':
234- # fig = bokeh_piechart(source)#, figure=figure)
235- # row1.children[1] = fig
236- #else:
237- #print(y_keys, df.data['colors'])
229+
238230 y_keys = ydata_spec .data ['y_keys' ]
239231 fill_colors = ydata_spec .data ['colors' ]
240232 fig = bokeh_barchart (source , y = y_keys , factors = y_keys , legend_labels = y_keys , fill_color = fill_colors , title = f'Q: { question } ' , orientation = 'vertical' )#df.data['factors'], legend_labels='legend_labels')#, figure=figure)
241- #fig.margin = MARGINS
242233 #fig2 = bokeh_barchart(source, y=y_keys, factors=y_keys, legend_labels=y_keys, fill_color=fill_colors, title=question, orientation='horizontal')#'horizontal')#df.data['factors'], legend_labels='legend_labels')#, figure=figure)
243- #fig2.margin = MARGINS
244234
245235 #tab1 = ("Vertical Bar chart", pn.pane.Bokeh(fig))
246236 #tab2 = ("Horizontal Bar chart", pn.pane.Bokeh(fig))
@@ -251,30 +241,19 @@ def update(target, event, charttype=1):
251241 target .object = fig
252242
253243 #row2.objects[ob_index] = tabs
254- # Bokeh layout
255- #tab1 = Panel(child=fig, title="Vertical Bar chart")
256- #tab2 = Panel(child=fig, title="Horizontal Bar chart")
257- #tab3 = Panel(child=fig, title="Pie chart")
258- #tabs = Tabs(tabs=[tab1, tab2, tab3])
259- #row2.children[ob_index] = tabs
260- #add_legend_at(fig)
261-
262- def update_corr (target , event ):#*events):
244+
245+
246+ def update_corr (target , event ):
263247 """Update the correlation plot"""
264248
265249 print (event )
266250 ob_index = 1
267251 df , display_options , marker_scale = select_data_corr ()
268252 fig_corr = bokeh_corr_plot (df , ** display_options )
269253 leg_corr = create_legend_corr (fig_corr , colors = df .data ['color' ], scale_m = marker_scale )
270- #fig_corr.margin = MARGINS
271254
272255 target .object = fig_corr
273- #row3.objects[ob_index] = pn.pane.Bokeh(fig_corr)
274- #row3.objects[ob_index+1] = pn.pane.Bokeh(leg_corr)
275- # bokeh layout
276- #row3.children[ob_index] = fig_corr
277- #row3.children[ob_index+1] = leg_corr
256+
278257
279258
280259
@@ -290,27 +269,22 @@ def update_corr(target, event):#*events):
290269fig3 = pn .pane .Bokeh (bokeh_barchart (start_display_data , y = y_keys , factors = y_keys , legend_labels = y_keys ,
291270 fill_color = fill_colors , title = f'Q: { question } ' , orientation = 'vertical' ))#factors=start_display_data.data['factors'])
292271
293- #fig.margin = MARGINS
294272start_corr_data , display_options , marker_scale = select_data_corr ()
295273fig_corr_1 = bokeh_corr_plot (start_corr_data , ** display_options )
296274fig_corr = pn .pane .Bokeh (fig_corr_1 )
297275leg_corr = pn .pane .Bokeh (create_legend_corr (fig_corr_1 , colors = start_corr_data .data ['color' ], scale_m = marker_scale ))
298- #fig_corr.margin = MARGINS
299- #fig2 = bokeh_barchart(source_corr)
300-
301- #fig2 = bokeh_multi_scatter(source2, marker_size=[int(x)+6 for x in xs[1])
302276
303277
304278def generate_bar_controls ():
305- controls_bar = [question_select , multi_choice ]
279+ controls_bar = [question_select , multi_choice , multi_choice_method ]
306280 return controls_bar
307281
308282def generate_corr_controls ():
309283 controls_corr = [question_select2 , question_select3 ]
310284 return controls_corr
311285
312286md_text_global_filter = ("# Global data filters\n Select some data filters to apply. "
313- "YYou can filter for research area and or data generation method." )
287+ "You can filter by research area and or by data generation method." )
314288
315289md_text_barchart = ("# Overview\n Use this area to explorer the results for each survey question. "
316290 "Use the dropdown menus to select the question of interest." )
@@ -320,63 +294,39 @@ def generate_corr_controls():
320294
321295md_text_button = ("# Further charts\n " )
322296
323- # Dashboard layout
297+ ####################
298+ # Dashboard layout #
299+ ####################
324300
325- # for spaces: https://docs.bokeh.org/en/latest/docs/reference/models/layouts.html#spacer
326301controls_bar = generate_bar_controls ()
327302for control in controls_bar :
328303 #control.param.watch(update, ['value'], onlychanged=True)
329304 control .link (fig , callbacks = {'value' : update })
330305 control .link (fig2 , callbacks = {'value' : update })
331306 control .link (fig3 , callbacks = {'value' : update })
332-
333- #bokeh
334- #control.on_change('value', lambda attr, old, new: update())
307+ #control.link(tabs, callbacks={'value': update})
308+ control . link ( fig_corr , callbacks = { 'value' : update_corr })
309+
335310tab1 = ("Vertical Bar chart" , fig )
336311tab2 = ("Horizontal Bar chart" , fig2 )
337312tab3 = ("Pie chart" , fig3 )
338313tabs = construct_tabs ([tab1 , tab2 , tab3 ])
339314
340315controls_corr = generate_corr_controls ()
341316for control in controls_corr :
342- #control.param.watch(update_corr, ['value'], onlychanged=True)
343317 control .link (fig_corr , callbacks = {'value' : update_corr })
344- #bokeh
345- #control.on_change('value', lambda attr, old, new: update_corr())
346-
347- '''
348- # Layout bokeh only
349- inputs = column(*controls_bar, width=800)
350- inputs_corr = column(*controls_corr, width=200)
351-
352- # create tabs
353- tab1 = Panel(child=fig, title="Vertical Bar chart")
354- tab2 = Panel(child=fig, title="Horizontal Bar chart")
355- tab3 = Panel(child=fig, title="Pie chart")
356- tabs = Tabs(tabs=[tab1, tab2, tab3])
357-
358- row1 = column(desc, md_text_global_filter, row(inputs), sizing_mode="scale_both")
359- row2 = row(tabs)
360- row3 = row(inputs_corr, fig_corr, leg_corr)
361-
362- layout = column(row1, md_text_barchart, row2, md_text_corrchart, row3, row(button_bar), sizing_mode="scale_both")
363- '''
364318
365319# Layout with Panel
320+ # We provide the layout in this explicit way and not all in one list because first we addresed the objects
321+ # over the rows name, now this may be obsolete
322+
366323inputs = pn .Column (* controls_bar , width = 800 )
367324inputs_corr = pn .Column (* controls_corr , width = 800 )
368325
369-
370326row1 = pn .Column (desc , md_text_global_filter , pn .Row (inputs ), sizing_mode = "scale_both" )
371327row2 = pn .Row (tabs )
372328row3 = pn .Column (inputs_corr , pn .Row (fig_corr , leg_corr ))
373329row4 = pn .Row (button_bar )
374- layout = pn .Column (row1 , md_text_barchart , row2 , md_text_corrchart , row3 , row4 , sizing_mode = "scale_both" )
375-
376- layout .servable ()
377- #row1 = pn.Row(inputs, tabs, fig_corr, inputs_corr)
378- #first = pn.Column(desc, row1, sizing_mode="scale_both")
379- #layout = pn.Column(first, pn.Row(button_bar), sizing_mode="scale_both")
330+ layout = pn .Column (row1 , md_text_barchart , row2 , md_text_corrchart , row3 , md_text_button , row4 , sizing_mode = "scale_both" )
380331
381- #curdoc().add_root(layout)
382- #curdoc().title = "HMC Survey Dashboard"
332+ layout .servable ()
0 commit comments