예제 #1
0
    def render_ui(self) -> None:
        if has_input_ui_renderer(self._input_class):
            # The input model has a rendering function
            # The rendering also returns the current state of input data
            self._session_state.input_data = self._input_class.render_input_ui(  # type: ignore
                st, self._session_state.input_data
            ).dict()
            return

        required_properties = self._input_class.schema(by_alias=True).get(
            "required", []
        )

        for property_key in self._schema_properties.keys():
            streamlit_app = st.sidebar
            property = self._schema_properties[property_key]

            if not property.get("title"):
                # Set property key as fallback title
                property["title"] = name_to_title(property_key)

            if property_key in required_properties:
                streamlit_app = st

            try:
                self._store_value(
                    property_key,
                    self._render_property(streamlit_app, property_key, property),
                )
            except Exception:
                pass
예제 #2
0
 def _render_object_input(self, streamlit_app: st, key: str, property: Dict) -> Any:
     properties = property["properties"]
     object_inputs = {}
     for property_key in properties:
         property = properties[property_key]
         if not property.get("title"):
             # Set property key as fallback title
             property["title"] = name_to_title(property_key)
         # construct full key based on key parts -> required later to get the value
         full_key = key + "." + property_key
         object_inputs[property_key] = self._render_property(
             streamlit_app, full_key, property
         )
     return object_inputs
예제 #3
0
    + " You can explore some examples below 👇"
)

DEFAULT_DEMO = "hello_world"

demos = [str(dir) for dir in filter(os.path.isdir, os.listdir(os.curdir))]

title_to_demo = {}

demo_titles = []
default_index = 0
for i, demo in enumerate(demos):
    if demo == DEFAULT_DEMO:
        # Use hello world as default
        default_index = i
    demo_title = name_to_title(demo)
    title_to_demo[demo_title] = demo
    demo_titles.append(demo_title)

selected_demo_title = st.selectbox(
    "Select Demo", options=demo_titles, index=default_index
)
selected_demo = title_to_demo[selected_demo_title]


def open_link(url: str, new_tab: bool = True) -> None:
    """Hack to open a new web page with a streamlit button."""
    from bokeh.models.widgets import Div

    # From: https://discuss.streamlit.io/t/how-to-link-a-button-to-a-webpage/1661/3
    if new_tab: