예제 #1
0
 def _render_multi_enum_input(self, streamlit_app: st, key: str,
                              property: Dict) -> Any:
     streamlit_kwargs = self._get_default_streamlit_input_kwargs(
         key, property)
     reference_item = schema_utils.resolve_reference(
         property["items"]["$ref"], self._schema_references)
     # TODO: how to select defaults
     return streamlit_app.multiselect(**streamlit_kwargs,
                                      options=reference_item["enum"])
예제 #2
0
    def _render_object_list_input(
        self, streamlit_app: st, key: str, property: Dict
    ) -> Any:

        # TODO: support max_items, and min_items properties

        # Add title and subheader
        streamlit_app.subheader(property.get("title"))
        if property.get("description"):
            streamlit_app.markdown(property.get("description"))

        streamlit_app.markdown("---")

        current_list = self._get_value(key)
        if not current_list:
            current_list = []

        object_reference = schema_utils.resolve_reference(
            property["items"]["$ref"], self._schema_references
        )
        input_data = self._render_object_input(streamlit_app, key, object_reference)

        streamlit_app.markdown("---")

        with streamlit_app.beta_container():
            clear_col, add_col = streamlit_app.beta_columns([1, 2])

            with clear_col:
                if streamlit_app.button("Clear Items", key=key + "-clear-items"):
                    current_list = []

            with add_col:
                if (
                    streamlit_app.button("Add Item", key=key + "-add-item")
                    and input_data
                ):
                    current_list.append(input_data)

        streamlit_app.write(current_list)
        return current_list