Skip to content

Story

ipyvizzustory.env.st.story

A module for working with presentation stories in Streamlit environment.

ipyvizzustory.env.st.story.Story

Bases: Story

A class for representing a presentation story in Streamlit environment.

Source code in src/ipyvizzustory/env/st/story.py
class Story(StoryLib):
    """A class for representing a presentation story in `Streamlit` environment."""

    def __init__(self, data: Data, style: Optional[Style] = None):
        """
        Presentation Story constructor.

        Args:
            data: Data set for the whole presentation story.
                After initialization `data` can not be modified,
                but it can be filtered.
            style: Style settings for the presentation story.
                `style` can be changed at each presentation step.
        """

        super().__init__(data=data, style=style)

    def _get_width_height(self) -> Tuple[Optional[int], int]:
        if self._size.width == "100%" and StorySize.is_pixel(self._size.height):
            return None, int(float(self._size.height[:-2]))  # type: ignore
        try:
            return self._size.get_width_height_in_pixels()
        except ValueError as error:
            if str(error) == StorySize.ERROR_MSG_WIDTH_AND_HEIGHT:
                raise ValueError(
                    f"{StorySize.ERROR_MSG_WIDTH_AND_HEIGHT} or width should be 100%"
                ) from error
            raise error

    def play(self) -> None:
        """A method for displaying the assembled `HTML` code in `Streamlit` environment."""

        _width, _height = self._get_width_height()

        html(
            self.to_html(),
            width=_width,
            height=_height,
        )

__init__(data, style=None)

Presentation Story constructor.

Parameters:

Name Type Description Default
data Data

Data set for the whole presentation story. After initialization data can not be modified, but it can be filtered.

required
style Optional[Style]

Style settings for the presentation story. style can be changed at each presentation step.

None
Source code in src/ipyvizzustory/env/st/story.py
def __init__(self, data: Data, style: Optional[Style] = None):
    """
    Presentation Story constructor.

    Args:
        data: Data set for the whole presentation story.
            After initialization `data` can not be modified,
            but it can be filtered.
        style: Style settings for the presentation story.
            `style` can be changed at each presentation step.
    """

    super().__init__(data=data, style=style)

play()

A method for displaying the assembled HTML code in Streamlit environment.

Source code in src/ipyvizzustory/env/st/story.py
def play(self) -> None:
    """A method for displaying the assembled `HTML` code in `Streamlit` environment."""

    _width, _height = self._get_width_height()

    html(
        self.to_html(),
        width=_width,
        height=_height,
    )