Exemplo n.º 1
0
def setupTable(cds, template=None):
    """
    """
    if template is None:
        # Define our color format/template
        #   This uses Underscore’s template method and syntax.
        #   http://underscorejs.org/#template
        template = """
                    <b>
                    <div style="background:<%=
                        (function ageColorer(){
                            if(ageStatement){
                            return("#ff0000;opacity:0.25;")
                            }
                            else{
                            return("none;")
                            }
                        }()) %>;">
                        <%= value %>
                    </div>
                    </b>
                    """
    elif template == 'none':
        template = ""
    else:
        template = template

    formatter = HTMLTemplateFormatter(template=template)

    # Now we construct our table by specifying the columns we actually want.
    #   We ignore the 'ageStatement' row for this because we
    #   just get at it via the formatter/template defined above
    labelCol = TableColumn(field='labels', title='Parameter', sortable=False)
    valueCol = TableColumn(field='values',
                           title='Value',
                           sortable=False,
                           formatter=formatter)
    cols = [labelCol, valueCol]

    nRows = len(cds.data['labels'])

    # Now actually construct the table
    dtab = DataTable(columns=cols, source=cds)

    # THIS IS SO GOD DAMN IRRITATING
    #   It won't accept this in a theme file because it seems like there's a
    #   type check on it and 'None' is not the 'correct' type
    dtab.index_position = None

    # This is also irritating
    #   Specify a css group to be stuffed into the resulting div/template
    #   which is then styled by something else. Can't get it thru the theme :(
    dtab.css_classes = ["nightwatch_bokeh_table"]

    return dtab, nRows
Exemplo n.º 2
0
def make_parameter_table(p_table,
                         data,
                         headers,
                         table_width=None,
                         table_height=None):
    if (data == None or headers == None):
        print('Making default data')
        data = dict(
            col1=[i for i in range(20)],
            col2=[i * i for i in range(20)],
        )
        headers = dict(col1='Title 1', col2='Title 2')

    source = ColumnDataSource(data)

    columns = []
    for key in data:
        if (key not in headers):
            raise ValueError(f'Header dictionary does not contain: {key}')
        columns = columns + [TableColumn(field=key, title=headers[key])]
    if (p_table == None):
        if (table_width == None or table_height == None):
            p_table = DataTable(source=source,
                                columns=columns,
                                editable=False,
                                index_position=None)
        else:
            p_table = DataTable(source=source,
                                columns=columns,
                                width=table_width,
                                height=table_height,
                                editable=False,
                                index_position=None)
    else:
        p_table.source = source
        p_table.columns = columns
        p_table.editable = False
        p_table.index_position = None
        if (table_width is not None):
            p_table.width = table_width
        if (table_height is not None):
            p_table.height = table_height

    return p_table
Exemplo n.º 3
0
def programming(db):
    # Cumulative and by individual.

    source = ColumnDataSource(ColumnDataSource.from_df(db.reset_index()))
    #source.add(db.index, 'index')

    columns = [
        TableColumn(field="ID", title="ID"),
        TableColumn(field="TFC_complete", title="T4C complete"),
        TableColumn(field="TFC_sessions", title="T4C sessions"),
        TableColumn(field="partial_college_prerelase_total",
                    title="College programming"),
        TableColumn(field="GED_prerelease", title="GED"),
        TableColumn(field="certificate_programs_prerelease",
                    title="Certificate programs")
    ]

    data_table = DataTable(source=source, columns=columns, width=800)
    data_table.index_position = None
    table = widgetbox(data_table)
    #curdoc().add_root(row(controls, table))
    #curdoc().title = "Export CSV"
    return table