Esempio n. 1
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
df = load_data()
default_feature = df.columns[0]
source_df = ColumnDataSource(df)

# CREATE NEW FEATURES HERE

# Page title
title = Div(text="""<h1>Dive into the Boston House Price Dataset</h1> <br>
<p>This simple dashboard gives an overview of the capabilities of Bokeh
for data visualization. <br> Learn more about this dataset
<a href="https://www.cs.toronto.edu/~delve/data/boston/bostonDetail.html">here</a>.</p>"""
            )

# Datatable - Display raw data
table = DataTable(source=source_df, sortable=True)
table.columns = [TableColumn(field=col, title=col) for col in df.columns]

# Data - Compute correlation matrix & define source
df_corr = df.corr()
df_corr.index.name = 'axis1'
df_corr.columns.name = 'axis2'
df_corr = df_corr.stack().rename("value").reset_index()
source_df_corr = ColumnDataSource(df_corr)

# Figure - Features correlation heatmap
figure_heatmap = figure(title="Correlation plot",
                        plot_width=600,
                        plot_height=600,
                        x_range=list(df_corr.axis1.drop_duplicates()),
                        y_range=list(df_corr.axis2.drop_duplicates()))
mapper = LinearColorMapper(palette=colors, low=-1, high=1)
Esempio n. 3
0
    global source
    '''Generate a 2D toy dataset as pandas Dataframe'''
    data = {}
    data['x'] = np.random.randint(-10, 10, 100)
    data['y'] = np.random.randint(-10, 10, 100)
    source.data.update(data)


# Define source data (updated at each call of generate_new_data)
source = ColumnDataSource()
generate_new_data(source)

# Create data table (linked to source)
table = DataTable(source=source, sortable=True)
table.columns = [
    TableColumn(field=col, title=col) for col in source.data.keys()
]

# Create button and callback (update source)
button = Button(label='Generate new data points', button_type='primary')
button.on_click(generate_new_data)

# Create a scatter plot (display source)
p = figure(title='2D toy dataset',
           x_axis_label='X axis',
           y_axis_label='Y axis')
p.circle(x='x',
         y='y',
         source=source,
         selection_color='red',
         nonselection_alpha=0.2)
        dict(image=[np.flip(x, 0) for x in data['image']],
             label=list(data['label'])))
    df = pd.DataFrame.from_records(data)
    return df


# Data - Load raw data & define source
df = load_data()
source_df = ColumnDataSource(df.head(500))

# CREATE NEW FEATURES HERE

# Page title
title = Div(text="""<h1>Dive into the Fashion MNIST Dataset</h1> <br>
<p>This simple dashboard gives an overview of the capabilities of Bokeh
for data visualization. <br> Learn more about this dataset
<a href="https://research.zalando.com/welcome/mission/research-projects/fashion-mnist/">here</a>.</p>"""
            )

# Datatable - Display raw data
table = DataTable(source=source_df, sortable=True)
table.columns = [TableColumn(field=col, title=col) for col in ['label']]

# Figure - Visualize sample image
figure_image = figure(plot_height=250, plot_width=250)
figure_image.image(image='image', source=source_df, x=0, y=0, dw=28, dh=28)

# Define layout and add to document
layout = column(title, row(table, figure_image))
curdoc().add_root(layout)
Esempio n. 5
0
 def create(self) -> DataTable:
     dt = DataTable(source=ColumnDataSource(self.df), **self.params)
     dt.columns = self.create_columns()
     return dt