示例#1
0
    def plot_table(self, **params):
        try:
            from bokeh.models.widgets import DataTable, TableColumn
            df, metrics = self._handle_data(**params)

            columns = list()
            for col in df.columns.to_list():
                columns.append(TableColumn(field=col, title=col))
            source = ColumnDataSource(df)
            p2 = DataTable(columns=columns,
                           source=source,
                           fit_columns=True,
                           max_height=(self.plot_height - 20),
                           max_width=(self.plot_width - 40),
                           index_width=0)
            p2.width = (self.plot_width - 30)
            p2.height = (self.plot_height - 20)
            return p2
        except Exception as e:
            return f"<br><br> Plot error: <br> {str(e)}"
示例#2
0
def _metadata_table(table_keys, viewer_cds, table_width=500, shortcds_name='shortcds', selectable=False):
    """ Returns bokeh's (ColumnDataSource, DataTable) needed to display a set of metadata given by table_keys.
    
    """
    special_cell_width = { 'TARGETID':150, 'MORPHTYPE':70, 'SPECTYPE':70, 'SUBTYPE':60, 
                         'Z':50, 'ZERR':50, 'Z_ERR':50, 'ZWARN':50, 'ZWARNING':50, 'DELTACHI2':70 }
    special_cell_title = { 'DELTACHI2': 'Δχ2(N+1/N)' }
    
    table_columns = []
    cdsdata = dict()
    for key in table_keys:
        if key in special_cell_width.keys():
            cell_width = special_cell_width[key]
        else:
            cell_width = table_width//len(table_keys)
        if key in special_cell_title.keys():
            cell_title = special_cell_title[key]
        else:
            cell_title = key
        if 'mag_' in key:
            cdsdata[key] = [ "{:.2f}".format(viewer_cds.cds_metadata.data[key][0]) ]
        elif 'CHI2' in key:
            cdsdata[key] = [ "{:.1f}".format(viewer_cds.cds_metadata.data[key][0]) ]
        elif key in ['Z', 'ZERR', 'Z_ERR']:
            cdsdata[key] = [ "{:.4f}".format(viewer_cds.cds_metadata.data[key][0]) ]
        else:
            cdsdata[key] = [ viewer_cds.cds_metadata.data[key][0] ]
        table_columns.append( TableColumn(field=key, title=cell_title, width=cell_width) )
    shortcds = ColumnDataSource(cdsdata, name=shortcds_name)
    # In order to be able to copy-paste the metadata in browser,
    #   the combination selectable=True, editable=True is needed:
    editable = True if selectable else False
    output_table = DataTable(source = shortcds, columns=table_columns,
                             index_position=None, selectable=selectable, editable=editable, width=table_width)
    output_table.height = 2 * output_table.row_height
    return (shortcds, output_table)
示例#3
0
文件: makehtml.py 项目: sparce/NAF
source = ColumnDataSource(df)
original_source = ColumnDataSource(df)

numform = NumberFormatter(format='0.00')

strcolumns = [
    TableColumn(field=x, title=x) for x in ["coach", "race", "nation"]
]
numcolumns = [
    TableColumn(field=x, title=x, formatter=numform)
    for x in ["mu", "phi", "value"]
]

data_table = DataTable(source=source, columns=strcolumns + numcolumns)

data_table.height = 1000
data_table.width = 500

# callback code to be used by all the filter widgets
# requires (source, original_source, race_select_obj,target_object)
combined_callback_code = """
var data = source.get('data');
var original_data = original_source.get('data');
var race = race_select_obj.get('value');
console.log("race: " + race);

for (var key in original_data) {
    data[key] = [];
    for (var i = 0; i < original_data['race'].length; ++i) {
        if (race === "ALL" || original_data['race'][i] === race) {
            data[key].push(original_data[key][i]);