# The How to: Visualising an html file on PC or Browser

I was learning about plotly and plotly.express and started reading of how instead of using the show() method with my figure


I could use the write_html() method to save the file in HTML on my pc.

Like this:


But then I was not able to visualize that figure on my pc by double clicking on it or with my web browser by opening it with the browser app. In Both Cases I would just see HTML code. So How do I visualise that HTML code properly? How do I do that?

  • I guess for visualisation on my pc I could use an HTML interpreter?

    • Could this be done? Or is Plotly confined for usage within a browser
  • But what about opening the html file in the web browser, is an html interpreter like VScode necessary or can the code be loaded directly into the browser somehow?

For context, below is my html file generating code written in python:

from random import randint
import plotly.express as px

class Die:
    """A class representing a single die."""

    def __init__(self, num_sides=6):
        """Assume a six-sided die."""
        self.num_sides = num_sides

    def roll(self):
        """Return a random value between 1 and number of sides."""
        return randint(1,self.num_sides)

D6= Die()
D10= Die(10)

# Make some rolls, and store results in a list.
results = []

for roll_num in range(50000):
 result = D6.roll()+ D10.roll()

# Analyze the results.
frequencies = []
max_result= D6.num_sides + D10.num_sides
poss_results = range(2, max_result+1)
for value in poss_results:
    frequency = results.count(value)

# Visualize the results.
fig = px.bar(x=poss_results, y=frequencies,title="Results of rolling 1 D6 and 1 D10 50000 times",labels= {"x":"Results","y":"Frequencues of results"})

Make sure the file name ends in “.html”, otherwise browsers are not going to guess what kind of file it is.

Right,I completely ignored that. Thanks.It worked.