Python Forum
How to merge my two python scripts in one ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to merge my two python scripts in one ?
#1
I want to create a web interface with a python srcipt in order to generate different graph from many CSV.

For that, I use pandas, plotly avec ipywidgets as librarys and Jupyter Notebook.

My first script allow to display a CSV according to the server and the date choose in the dropdowns :

from ipywidgets import interact, Dropdown
from ipywidgets import widgets
from IPython.display import display
import plotly.express as px
import pandas as pd
from ipywidgets.embed import embed_minimal_html
import sys
import os

###################### Déclarations des widgets ######################

button = widgets.ToggleButton(description='click me')
out = widgets.Output(layout=widgets.Layout(border = '1px solid black'))

Server = os.listdir('/home/tim/Bureau/Servers/')
ServerList = widgets.Dropdown(options = (Server))

Date = ['2019-10', '2019-11', '2019-12', '2020-01']
DateList = widgets.Dropdown(options = (Date))


@interact(ServersList = Server, DatesList = Date)
def print_all(ServersList, DatesList):
    Test = os.listdir('/home/tim/Bureau/Servers'+ '/'+ ServersList+ '/'+ DatesList+'/')
    Path = os.path.join('/home/tim/Bureau/Servers'+ '/'+ ServersList+ '/'+ DatesList+'/' + str(Test).strip("[]").strip("''"))
    display(Path)

    df = pd.read_csv(Path)
    df.head()


    fig = px.line(df, x = 'Date', y = 'Total', title='DF command graph')
    fig.add_scatter(mode='markers+lines')
    
    display(df)
This script works perfectly, the output is :
[Image: ss7u.png]


My second script allow to display the CSV and trace a graph according to the FS choose in the dropdown. The script is :

import ipywidgets as widgets
from ipywidgets import interactive
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px

df = pd.read_csv('/home/tim/Bureau/Servers/Server1/2019-10/Test1.txt')


items = ['All']+sorted(df['FS'].unique().tolist())


def view(x=''):
    if x=='All': display(df)
    display(df[df['FS']==x])

    fig = px.line(df[df['FS']==x], x = 'Date', y ='Total', title='DF command graph')
    #fig.add_scatter(x=df['Date'], y=df['Used'])
    fig.update_traces(mode='markers+lines')
    fig.show();

w = widgets.Dropdown(options=items)
interactive(view, x=w)
This script works perfectly too. The result is :
[Image: grch.png]


So my question is : How to merge my two script to have the three dropdown at the same time in order to choose the server, the date and the FS needed ?

Thanks !
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to us python.exe from our network to run scripts cubangt 3 859 Aug-17-2023, 07:53 PM
Last Post: deanhystad
  Сombine (Merge) word documents using python-docx Lancellot 1 11,516 May-12-2021, 11:07 AM
Last Post: toothedsword
  Running python scripts from github etc pacmyc 7 3,695 Mar-03-2021, 10:26 PM
Last Post: pacmyc
  Reading SQL scripts from excel file and run it using python saravanatn 2 2,547 Aug-23-2020, 04:49 PM
Last Post: saravanatn
  No Scripts File present after python installation ag2207 5 4,882 Jul-30-2020, 11:11 AM
Last Post: buran
  How can I Open and close .py file from python scripts SayHiii 9 5,730 Dec-17-2019, 06:10 AM
Last Post: Malt
  autostart python scripts in background (Windows10) john36 4 7,684 Oct-01-2019, 01:36 PM
Last Post: john36
  Run macros of excel sheet from python scripts shubhamjainj 3 10,447 May-01-2019, 08:40 AM
Last Post: buran
  Possible to run Python scripts from oracle? dglass 8 9,346 Sep-06-2018, 05:14 PM
Last Post: dglass
  Keyboard Maestro has problem importing python scripts bobsmith76 3 4,495 Aug-29-2018, 08:10 PM
Last Post: bobsmith76

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020