11

Is it possible to use an interactive graph created with Python package Plotly in PowerPoint? Is it possible to insert a plotly output in a slide?

Elena Greg
  • 1,061
  • 1
  • 11
  • 26
  • I don't know Plotly but it sounds like you're going to need to create an image, save it to a file like a PNG and then you can import that PNG into Powerpoint. – Andy Lester May 13 '21 at 13:22
  • 1
    I would like to have an interacting image https://plotly.com/python/line-charts/ reacting to mouse and showing labels. – Elena Greg May 13 '21 at 13:25

3 Answers3

9

To my knowledge and experience, if you want to show the interactive image within PPT, my current answer is no. Because previously I tried to do the same thing for Plotly or Bokeh figures. I looked around and in the end, I saw somebody answered on a Microsoft discussion page, the answer was NO.

But one thing that works is that you can input your figure (html file) as a hyperlink within the ppt. Then when you click it, it opens on your browser, you can still interact with it, although it is not in ppt!

If you are making a presentation via online platforms like Zoom, you can just switch the screen that you are sharing.

Jeremy
  • 849
  • 6
  • 15
2

There used to be a PowerPoint add-in that made it possible to integrate interactive charts published on plotly Chart Studio into the presentation. Unfortunately, this add-in is no longer available.

EDIT: I found a workaround to get interactiv plotly charts into my PowerPoint Slides

How to:

  1. Create a Plotly chart studio account
  2. Publish your chart on chart studio like described here
  3. Open PowerPoint and install the Add-In "Webviewer"
  4. Insert the public URL of yout chart from Plotly chart studio

Disadvantage: It only works if the plug-in is installed and Internet access is available.

Jan Schmidt
  • 62
  • 1
  • 7
-1

I was surfing the internet and found your question and then ask chatGPT for the same inquiry. It tells me a new library that does the job. https://pypi.org/project/plotlyPowerpoint/

Here's a representation

from pptx import Presentation
import pandas as pd
from pydataset import data
import plotlyPowerpoint as pp

############
## Prepare Data
############

#load datasets
df = data('InsectSprays')
df2 = data("JohnsonJohnson")

#Data transformation
df['m2'] = df['count'] * 1.1
df2['year'] = df2['time'].astype(int)
df2 = df2.groupby(['year']).agg({'JohnsonJohnson': 'mean'}).reset_index()

#load presentation
prs = Presentation("template.pptx")

#set the slide we are after - the first slide in the master layout is at index 0
slide = prs.slides.add_slide(prs.slide_layouts[0])

#print index and name
for shape in slide.placeholders:
    print('%d %s' % (shape.placeholder_format.idx, shape.name))

pp.setTemplate("path_to_template")

charts = [
    { #Line Chart - stock prices
        "data": df2,
        "type": "line",
        "name": "Stock Prices by Company",
        "metrics": [
            {"name": "JohnsonJohnson", "prettyName": "Stock Price", "method": "mean"}
        ],
        "axis": "year",
        "x-axis-title": 'Year',
        "y-axis-title": "Average Stock Price",
        "description": "Grouping by additional variables is easy",
        "filters": [
            {"variable": "year", "operation": ">=", "value": "1970", "type":"int"}
        ],
        "item-index": {
            'slide': 0,
            'title': 0,
            'chart': 10,
            'description': 12
        }
    },
    { #Bar chart of insect sprays
        "data": df,
        "type": "bar",
        "name": "Avg Spray Effictiveness by Type",
        "metrics": [
            {"name": "count", "prettyName": "Effectiveness", "method": "mean"},
            {"name": "m2", "prettyName": "Effectiveness 2", "method": "mean"}
        ],
        "axis": "spray",
        "x-axis-title": "Effectiveness",
        "size": "wide",
        "description": "this slide has data on it!",
        'options': {
            'orientation': 'horizontal',
            'color-grouping': 'metric'
        },
        "item-index": {
            'slide': 0,
            'title': 0,
            'chart': 10,
            'description': 12
        }
    }
]

#run function
pp.createSlides(charts)
Nemra Khalil
  • 69
  • 1
  • 6