WS

Webslides Documentation


About Webslides is a Python package that creates HTML presentations like this one.
It enables easy sharing of Python-generated content such as charts, other visuals and data
Contents This presentation demonstrates features of the HTML format and should help you get started
PyPi https://pypi.org/project/webslides/


19 Apr. 2023

Contents

WHY

Advantages over Powerpoint  
    1. Dynamic pagelength 💡
    2. Interactive content 💡
    3. Any HTML content will render 💡
    4. Styled Pandas Dataframes 💡
    5. Super speed updates! 💡

HOW

Getting Started  
    6. Install and Import 💡
    7. Run Demo 💡
    8. Hello World 💡

Highlights summary 💡


WHY

Advantages over Powerpoint
    • Dynamic pagelength: - Pages can be as long (or short) as needed, like this one!
    • Interactive content: - Native Plotly graph ojects can be inserted as content, and they have many interactive features
    • Interactive content: - Try zooming in the by dragging a window in the plot. Or toggle visibility of a data series via the legend keys
    • Any HTML content will render: - For example this map
    • Styled Pandas Dataframes: - Wow, notice that max value marked red
    • Styled Pandas Dataframes: - Not to mention the lowest value, marked green
    • Super speed updates!: - A key advantage of this presentation form may be that updates only require the press of a button

HOW

Getting Started
    • Install and Import: - Nothing new here, good old pip install..
    • Run Demo: - ws.demo() will generate the html you are reading now
    • Hello World: - basic example, demonstrating all available parameters

WHY Advantages over Powerpoint: Dynamic pagelength

- Pages can be as long (or short) as needed, like this one!
Nothing much on this page really, that's why its so short 😉

- and adding a footer can be usefull too..
- ps. Have you noted the page navigation on the top right of the page?
- 💡: this marks pages with a highlight. If a page has no highlights (remarks in grey area) it is not shown in the highlight summary page nor marked in the table of contents

WHY Advantages over Powerpoint: Interactive content

- Native Plotly graph ojects can be inserted as content, and they have many interactive features
- Try zooming in the by dragging a window in the plot. Or toggle visibility of a data series via the legend keys

- Link to Plotly gallery here

WHY Advantages over Powerpoint: Any HTML content will render

- For example this map
Make this Notebook Trusted to load map: File -> Trust Notebook

- this map was created with Folium (docs)

WHY Advantages over Powerpoint: Styled Pandas Dataframes

- Wow, notice that max value marked red
- Not to mention the lowest value, marked green
  column1 column2 column3 column4 column5
row1 99% 31% 70% 92% 86%
row2 9% 50% 19% 98% 16%
row3 90% 8% 63% 71% 47%
row4 59% 73% 81% 2% 69%
row5 9% 68% 96% 45% 8%
row6 76% 60% 70% 88% 86%
row7 99% 82% 64% 87% 97%
row8 43% 93% 91% 98% 15%
row9 91% 70% 82% 29% 22%
row10 92% 88% 64% 10% 34%

- styling of a pandas dataframe can be done by creating a styler object and convert that to html
- ie. styled_df = df.style.background_gradient(cmap='Blues') and html = styled_df.to_html()

WHY Advantages over Powerpoint: Super speed updates!

- A key advantage of this presentation form may be that updates only require the press of a button
Very often data, analysis conlusions and other content is revised in getting to a final version of a presentation. Since all is in python script, updates of the presentation only requires the press of the â–¶ Run button.

- and pagination will automatically adjust if new content is inserted

HOW Getting Started: Install and Import

- Nothing new here, good old pip install..
#install package
pip install webslides

#import package
import webslides as ws

HOW Getting Started: Run Demo

- ws.demo() will generate the html you are reading now
#import
import webslides as ws

#create and open this demo.html in browser
ws.demo()

- html output file, in this case 'demo.html', is always saved to a directory 'wsout'

HOW Getting Started: Hello World

- basic example, demonstrating all available parameters

# imports
import webslides as ws
import plotly.graph_objects as go

# title page
title_page = {
    'img_url': '',
    'title': 'Title of Title Page',
    'summary': {'Summary item 1': 'item text 1', 'Summary item 2': 'item text 2'},
    'footer': ['- use custom title image via the img_url parameter', '- footer2']
}


# simple plotly fig
def simple_fig():
    x = list(range(1, 11))
    y1 = [2 * i for i in x]
    y2 = [3 * i for i in x]
    trace1 = go.Scatter(x=x, y=y1, mode='markers+lines', name='Line 1')
    trace2 = go.Scatter(x=x, y=y2, mode='markers+lines', name='Line 2')
    fig = go.Figure()
    fig.add_trace(trace1)
    fig.add_trace(trace2)
    fig.update_layout(title='Simple Plotly Line Figure with Two Lines')
    return fig


# content pages
content = {
    'Topcat A': {
        'Subcat X': [
            {
                'title': 'Page Title 1 - HTML body',
                'highlights': ['- highlight 1', '- highlight 2'],
                'body': 'Content 1: this is a <b>HTML string</b>',
                'footer': ['- footer 1a', '- <i>italic footer 1b</i>'],
                'show': True},
            {
                'title': 'Page Title 2 - No highlights',
                'body': 'Content 2: this is a <b>HTML string</b>',
                'footer': ['- Note: No highlights, so no lightbulb in the index page', '- <i>italic footer 2b</i>'],
                'show': True}
        ],
        'Subcat Y': [
            {
                'title': 'Page Title 3 - Plotly fig !',
                'highlights': ['- highlight 3', '- note: no footer on this page'],
                'body': simple_fig(),
                'show': True}
        ]
    },
    'Topcat B': {
        'Subcat Z': [
            {
                'title': 'Page Title 4 - Different topcat',
                'highlights': ['- highlight 5', '- highlight 6'],
                'body': 'Content 3',
                'footer': ['- footer 4a', '- footer 4b'],
                'show': True}
        ]
    }
}

# MAIN
ws.create(content=content
          , title_page=title_page
          , fname='webslides_hello_world.html'
          , open_in_browser=True
          , show_index_page=True
          , show_topcat=True
          , show_subcat=True
          , show_highlights_page=True
          , show_highlights_only=False)



- HTML allows to add javascript too, like the copy button. That's actually only one line of code