示例#1
0
    def __init__(self, tab_roles, title=None, sidebar_width=300, **kwargs):
        """
        Template that includes a title bar, places inputs in a sidebar, and outputs in
        a set of tabs

        :param tab_roles: List or dict of strings where each string specifies the name
            of the role corresponding to a single tab. If a list, the role name is
            also be used as the title of the corresponding tab. If a dict, the keys
            become the roles and the values become the tab labels
        :param title: Title bar title string
        :param sidebar_width: Sidebar width in pixels or as a css string
        """
        import dash_core_components as dcc

        self.title = title
        self.sidebar_width = sidebar_width
        if isinstance(tab_roles, (list, tuple)):
            self.tab_roles = OrderedDict([(role, role) for role in tab_roles])
        else:
            self.tab_roles = OrderedDict(tab_roles)

        self._valid_roles = ["input", "output"] + list(self.tab_roles.keys())
        self._tabs = dcc.Tabs(id=build_id("tabs"), value=self._valid_roles[2])

        super().__init__(**kwargs)
示例#2
0
    def __init__(self, tab_roles, title=None, sidebar_columns=4, **kwargs):
        """
        Template that includes a title bar, places inputs in a sidebar, and outputs in
        a set of tabs.

        :param tab_roles: List or dict of strings where each string specifies the name
            of the role corresponding to a single tab. If a list, the role name is
            also be used as the title of the corresponding tab. If a dict, the keys
            become the roles and the values become the tab labels
        :param title: Title bar title string
        :param sidebar_columns: Responsive width of input card in columns
            (out of 12 columns)
        """
        import dash_bootstrap_components as dbc

        # Set valid roles before constructor
        self.title = title
        self.sidebar_columns = sidebar_columns
        if isinstance(tab_roles, (list, tuple)):
            self.tab_roles = OrderedDict([(role, role) for role in tab_roles])
        else:
            self.tab_roles = OrderedDict(tab_roles)

        self._valid_roles = ["input", "output"] + list(self.tab_roles.keys())

        first_tab = next(iter(self.tab_roles))
        self._tabs = dbc.Tabs(id=build_id("tabs"), active_tab=first_tab)

        super().__init__(**kwargs)
示例#3
0
    def build_containered_component(cls, component, role=None):
        ddk = import_ddk()

        # Subclass could use bootstrap or ddk
        container_id = build_id("container")
        container = ddk.ControlItem(id=container_id, children=component)

        return container, "children"
示例#4
0
    def build_labeled_component(cls,
                                component,
                                label,
                                label_id=None,
                                role=None):
        import dash_bootstrap_components as dbc

        if not label_id:
            label_id = build_id("label")

        label_component = dbc.Label(
            id=label_id,
            children=[label],
            style={"display": "block"},
            className="h5",
        )
        container_id = build_id("container")
        container = dbc.FormGroup(id=container_id,
                                  children=[label_component, component])
        return container, "children", label_component, "children"
示例#5
0
    def build_labeled_component(cls, component, label, label_id=None, role=None):
        ddk = import_ddk()

        # Subclass could use bootstrap or ddk
        if not label_id:
            label_id = build_id("label")

        container = ddk.ControlItem(id=label_id, label=label, children=component)
        label_component = container
        label_property = "label"

        return container, "children", label_component, label_property
示例#6
0
 def build_labeled_component(cls,
                             component,
                             label,
                             label_id=None,
                             role=None):
     # Subclass could use bootstrap or ddk
     if not label_id:
         label_id = build_id("label")
     label_component = html.Label(id=label_id, children=label)
     container = html.Div(id="container",
                          children=[label_component, component])
     return container, "children", label_component, "children"
示例#7
0
    def __init__(
        self,
        df,
        columns=None,
        page_size=5,
        sort_mode=None,
        filterable=False,
        serverside=False,
        template=None,
        role="output",
    ):
        """

        :param df: Pandas DataFrame to be displayed in the DataTable
        :param columns: List of columns from df to display in the table. Defaults to
            all columns if not specified.
        :param page_size: The number of rows of df to display at once. If the number
            of rows exceeds this number, the table will display paging controls.
        :param sort_mode: Sort mode for table. One of:
            - None: no sorting
            - 'single': single column sorting
            - 'multi': multi-column sorting
        :param filterable: If True, display a filter box below each column in the
            table. If False (default), no filtering interface is displayed.
        :param serverside: If True, paging/sorting/filtering operations trigger
            a callback and are performed in Python and only the current displayed
            page is transferred to the client. If False (default), all rows of the table
            are sent to the client at startup and paging/sorting/filtering
            operations do not trigger a Python callback.
        :param template: Template to use to construct DataTable
        :param role: Template role that should be assigned to the constructed DataTable
        """
        if template is None:
            template = FlatDiv()

        if columns is None:
            columns = list(df.columns)

        self.page_size = page_size
        self.sort_mode = sort_mode
        self.filterable = filterable
        self.role = role

        self.serverside = serverside
        self.page_count = self._compute_page_count(df)

        if self.serverside:
            self.full_df = df
            self.df = self._compute_serverside_dataframe_slice(df)
        else:
            self.full_df = df
            self.df = df

        self.data, self.columns = self.convert_data_columns(self.df, columns)
        self.datatable_id = build_id()

        # Initialize args
        if self.serverside:
            args = self._build_serverside_input(template)
            output = self._build_serverside_output(template)
        else:
            args = self._build_clientside_input(template)
            output = self._build_clientside_output(template)

        super().__init__(args, output, template)
示例#8
0
    def build_containered_component(cls, component, role=None):
        import dash_bootstrap_components as dbc

        container_id = build_id("container")
        container = dbc.FormGroup(id=container_id, children=[component])
        return container, "children"