Tuesday, May 23, 2023

pyscript program to display csv data to html table

 

 To install httpserver: pip install httpserver

 

To Run  web server:  python3 -m http.server

 

Open http://0.0.0.0:8000/

 

python3 -m webbrowser http://0.0.0.0:8000/

 

It will open default index html page.

 

 <html>
    <head>
      <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
      <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
      <style>
        table {
          border-collapse: collapse;
          width: 100%;
        }
       
        th, td {
          text-align: left;
          padding: 8px;
        }
       
        tr:nth-child(even) {background-color: #f2f2f2;}
      </style>
    <py-env>
        - pandas
        - paths:
          - ./reportint.csv
          - ./reporttest.csv
      </py-env>
   
    </head>
  <body>
    <h1><b>Application overview TEST:</b></h1><br><br>
    <py-script>
      import pandas as pd
      column_names=["DATE","USER",'

COMMENT']
      a = pd.read_csv("reportint.csv",names=column_names)
      a.to_html("Table.htm")
      html_file = a.to_html()
      print(a.to_html())
     
    </py-script>
    <br><h2><b>Application overview INT:</b></h2><br>
    <py-script>
      import pandas as pd
      column_names=["DATE","USER",'COMMENT']
      a = pd.read_csv("reporttest.csv",names=column_names)
      a.to_html("Table.htm")
      html_file = a.to_html()
      print(a.to_html())
           
    </py-script>
  </body>
</html>
 

0 comments:

Post a Comment