bokeh.models.widgets.StringFormatter

Here are the examples of the python api bokeh.models.widgets.StringFormatter taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

0 Source : optbrowser.py
with GNU General Public License v3.0
from happydasch

    def _build_optresult_selector(self, optresults):
        # 1. build a dict with all params and all user columns
        data_dict = defaultdict(list)
        for optres in optresults:
            for param_name, _ in optres[0].params._getitems():
                param_val = optres[0].params._get(param_name)
                data_dict[param_name].append(param_val)

            for usercol_label, usercol_fnc in self._usercolumns.items():
                data_dict[usercol_label].append(usercol_fnc(optres))

        # 2. build a pandas DataFrame
        df = DataFrame(data_dict)

        # 3. now sort and limit result
        if self._sortcolumn is not None:
            df = df.sort_values(by=[self._sortcolumn], ascending=self._sortasc)

        if self._num_result_limit is not None:
            df = df.head(self._num_result_limit)

        # 4. build column info for Bokeh table
        tab_columns = []

        for colname in data_dict.keys():
            formatter = NumberFormatter(format='0.000')

            if (len(data_dict[colname]) > 0
                    and isinstance(data_dict[colname][0], int)):
                formatter = StringFormatter()

            tab_columns.append(
                TableColumn(
                    field=colname,
                    title=f'{colname}',
                    sortable=False,
                    formatter=formatter))

        cds = ColumnDataSource(df)
        selector = DataTable(
            source=cds,
            columns=tab_columns,
            height=150,  # fixed height for selector
            width=0,  # set width to 0 so there is no min_width
            sizing_mode='stretch_width',
            fit_columns=True)
        return selector, cds

    def build_optresult_model(self, _=None):