예제 #1
0
    def __init__(self, component_instance):
        def handle_model_change_helper(sidebar_mod, sidebar_data):
            return IndexCallbacks.handle_model_change(component_instance,
                                                      sidebar_data)

        super().__init__(
            component_instance=component_instance,
            callbacks=[
                ChimeCallback(  # If user toggles show_tables, show/hide tables
                    changed_elements={"show_tables": "value"},
                    dom_updates={
                        "SIR_table_container": "hidden",
                        "new_admissions_table_container": "hidden",
                        "admitted_patients_table_container": "hidden",
                    },
                    callback_fn=IndexCallbacks.toggle_tables),
                ChimeCallback(  # If the parameters or model change, update the text
                    changed_elements={"sidebar-store": "modified_timestamp"},
                    dom_updates={
                        "intro": "children",
                        "new_admissions_graph": "figure",
                        "new_admissions_table": "children",
                        "new_admissions_download": "href",
                        "admitted_patients_graph": "figure",
                        "admitted_patients_table": "children",
                        "admitted_patients_download": "href",
                        "SIR_graph": "figure",
                        "SIR_table": "children",
                        "SIR_download": "href",
                    },
                    callback_fn=handle_model_change_helper,
                    stores=["sidebar-store"],
                )
            ])
예제 #2
0
    def __init__(self, component_instance):
        sidebar = component_instance.components["sidebar"]
        sidebar_inputs = sidebar.input_value_map
        sidebar_input_types = sidebar.input_type_map

        def hash_changed_helper(hash_str=None, root_data=None):
            return RootCallbacks.hash_changed(sidebar_input_types, hash_str, root_data)

        def stores_changed_helper(root_mod, sidebar_mod, root_data, sidebar_data):
            return RootCallbacks.stores_changed(sidebar_inputs.keys(), root_mod, sidebar_mod, root_data, sidebar_data)
        super().__init__(
            component_instance=component_instance,
            callbacks=[
                ChimeCallback(
                    changed_elements={"location": "hash"},
                    dom_updates={"root-store": "data"},
                    callback_fn=hash_changed_helper,
                    stores=["root-store"],
                ),
                ChimeCallback(
                    changed_elements={"root-store": "modified_timestamp", "sidebar-store": "modified_timestamp"},
                    dom_updates={"location": "hash", **sidebar_inputs},
                    callback_fn=stores_changed_helper,
                    stores=["root-store", "sidebar-store"],
                ),
            ]
        )
예제 #3
0
    def __init__(self, language, defaults):
        changed_elements = OrderedDict(
            (key, _PROPERTY_OUTPUT_MAP.get(_INPUTS[key]["type"], "value"))
            for key in _INPUTS
            if _INPUTS[key]["type"] not in ("header",)
        )

        input_change_callback = ChimeCallback(
            changed_elements=changed_elements,
            dom_updates=OrderedDict(pars="children"),
            callback_fn=Sidebar.update_parameters,
        )
        super().__init__(language, defaults, [input_change_callback])
예제 #4
0
    def __init__(self, component_instance):
        def update_parameters_helper(*args, **kwargs):
            input_values = list(args)
            input_dict = dict(zip(component_instance.input_value_map.keys(), input_values))
            sidebar_data = input_values.pop(-1)
            if sidebar_data and input_dict and input_dict == sidebar_data["inputs_dict"]:
                raise PreventUpdate
            return SidebarCallbacks.update_parameters(component_instance, *args)

        super().__init__(
            component_instance=component_instance,
            callbacks=[
                ChimeCallback(
                    changed_elements=component_instance.input_value_map,
                    dom_updates={"sidebar-store": "data"},
                    callback_fn=update_parameters_helper,
                    stores=["sidebar-store"],
                )
            ]
        )
예제 #5
0
    def __init__(self, component_instance):
        def handle_model_change_helper(sidebar_mod, new_admissions_lock_zoom,
                                       admitted_patients_lock_zoom,
                                       SIR_lock_zoom, sidebar_data,
                                       new_admissions_relayout_data,
                                       admitted_patients_relayout_data,
                                       SIR_relayout_data):
            # parameter order: Inputs (sidebar_mod and all lock_zooms) followed by States (sidebar_data and all relayout_datas)
            # Order matters; callback_wrapper passes in Inputs before States
            lock_zoom_clicks = [
                new_admissions_lock_zoom, admitted_patients_lock_zoom,
                SIR_lock_zoom
            ]
            graphs_relayout_data = [
                new_admissions_relayout_data, admitted_patients_relayout_data,
                SIR_relayout_data
            ]
            return IndexCallbacks.handle_model_change(component_instance,
                                                      sidebar_data,
                                                      lock_zoom_clicks,
                                                      graphs_relayout_data)

        super().__init__(
            component_instance=component_instance,
            callbacks=[
                ChimeCallback(  # If user toggles show_tables, show/hide tables
                    changed_elements={"show_tables": "on"},
                    dom_updates={
                        "SIR_table_container": "hidden",
                        "new_admissions_table_container": "hidden",
                        "admitted_patients_table_container": "hidden",
                    },
                    callback_fn=IndexCallbacks.toggle_tables
                ),
                ChimeCallback(  # If the parameters or model change, update the text
                    changed_elements={
                        "sidebar-store": "modified_timestamp",
                        "new_admissions_lock_zoom": "n_clicks",
                        "admitted_patients_lock_zoom": "n_clicks",
                        "SIR_lock_zoom": "n_clicks"
                        },
                    dom_updates={
                        "intro": "children",
                        "new_admissions_graph": "figure",
                        "new_admissions_table": "children",
                        "new_admissions_download": "href",
                        "admitted_patients_graph": "figure",
                        "admitted_patients_table": "children",
                        "admitted_patients_download": "href",
                        "SIR_graph": "figure",
                        "SIR_table": "children",
                        "SIR_download": "href",
                    },
                    states={
                        "new_admissions_graph": "relayoutData",
                        "admitted_patients_graph": "relayoutData",
                        "SIR_graph": "relayoutData"
                        },
                    stores=["sidebar-store"],
                    callback_fn=handle_model_change_helper
                ),
                ChimeCallback( # If user presses the Lock Zoom Button, update outline / solid color
                    changed_elements={"new_admissions_lock_zoom": "n_clicks"},
                    dom_updates={"new_admissions_lock_zoom": "outline"},
                    callback_fn=IndexCallbacks.change_btn_color
                ),
                ChimeCallback(
                    changed_elements={"admitted_patients_lock_zoom": "n_clicks"},
                    dom_updates={"admitted_patients_lock_zoom": "outline"},
                    callback_fn=IndexCallbacks.change_btn_color
                ),
                ChimeCallback(
                    changed_elements={"SIR_lock_zoom": "n_clicks"},
                    dom_updates={"SIR_lock_zoom": "outline"},
                    callback_fn=IndexCallbacks.change_btn_color
                )
            ]
        )
예제 #6
0
파일: index.py 프로젝트: eigenvector7/chime
    def __init__(self, language, defaults):
        """
        """
        def handle_model_change_helper(pars_json):
            model = {}
            pars = None
            result = []
            viz_kwargs = {}
            if pars_json:
                pars = parameters_deserializer(pars_json)
                model = SimSirModel(pars)
                viz_kwargs = dict(
                    labels=pars.labels,
                    table_mod=7,
                    max_y_axis=pars.max_y_axis,
                )
            result.extend(self.components["intro"].build(model, pars))
            result.extend(self.components["tool_details"].build(model, pars))
            for df_key in ["admits_df", "census_df", "sim_sir_w_date_df"]:
                df = None
                if model:
                    df = model.__dict__.get(df_key, None)
                result.extend(prepare_visualization_group(df, **viz_kwargs))
            return result

        super().__init__(
            language,
            defaults,
            [
                ChimeCallback(  # If user toggles show_additional_projections, show/hide the additional intro content
                    changed_elements=OrderedDict(show_tool_details="value"),
                    dom_updates=OrderedDict(more_intro_wrapper="hidden"),
                    callback_fn=Index.toggle_tool_details),
                ChimeCallback(  # If user toggles show_tables, show/hide tables
                    changed_elements=OrderedDict(show_tables="value"),
                    dom_updates=OrderedDict(
                        SIR_table_container="hidden",
                        new_admissions_table_container="hidden",
                        admitted_patients_table_container="hidden",
                    ),
                    callback_fn=Index.toggle_tables),
                ChimeCallback(  # If the parameters or model change, update the text
                    changed_elements=OrderedDict(pars="children"),
                    dom_updates=OrderedDict(
                        intro="children",
                        more_intro="children",
                        new_admissions_graph="figure",
                        new_admissions_table="children",
                        new_admissions_download="href",
                        admitted_patients_graph="figure",
                        admitted_patients_table="children",
                        admitted_patients_download="href",
                        SIR_graph="figure",
                        SIR_table="children",
                        SIR_download="href",
                    ),
                    callback_fn=handle_model_change_helper)
            ])
        self.components = OrderedDict(
            header=Header(language, defaults),
            intro=Intro(language, defaults),
            tool_details=ToolDetails(language, defaults),
            visualizations=Visualizations(language, defaults),
            footer=Footer(language, defaults),
        )