<jupyter_start><jupyter_text>Use Plotly for better Graphs in my Panel- matplotlib - does not deal with long pathnames in the panel    - works fine outside my dashboard -<jupyter_code>import pandas as pd
# use plotly over matplotlib
pd.options.plotting.backend = "plotly"

#df = pd.read_csv("./ws_s3_usage.csv", index_col = [0])
df = pd.read_csv("./ws_s3_usage.csv")
# https://www.stackvidhya.com/add-row-to-dataframe/
def groom_df(df, bucket):
    ndf = df.loc[df['bucket'] == bucket]
    ndf = ndf.sort_values(by=['Gbytes'],ascending=False)
    ndf = ndf.reset_index(drop=True)
    ndf = ndf.round()
    total = ndf[['Gbytes', 'Costs']].sum()
    total.name = 'myTotals'
    ndf = ndf.append(total)
    ndf.at[ndf.index[-1], 'DirPrefix'] = 'TOTAL'
    ndf.fillna('', inplace=True)
    
    return ndf
    
my_df = groom_df(df,'ws-in')
my_df
cost_total = my_df.iloc[-1]['Costs']
cost_total
import panel as pn
#pn.extension()
pn.extension('plotly')
title = '# Fun with Buckets'
def get_bucket_list():
    '''
    ___________________________________________________________________
    THIS function returns watersmart S3 bucket names
    __________________________________________________________________
      - we only need THREE (3) buckets to do our work
    our buckets are used for our data inputs
          - ws-in: holds precip, NDVI, Temperature - inputs to our water models
          - ws-out: is our model outputs - sometimes just tiles and chips
          - ws-enduser: - is where we mosaic these into usable tifs, netcdfs, ugly-tarballs 
          ... etc ...
    '''
    b_list = ['ws-in', 'ws-out', 'ws-enduser']
    return b_list
bucket_select = pn.widgets.Select(name='IMPORTANT_BUCKET_LIST', options=get_bucket_list())
table_plot_select = pn.widgets.RadioBoxGroup(name='RadioBoxGroup', options=['Plot','Table'], inline=True)

display_select = pn.widgets.MultiSelect(width_policy='min', name='Display Select', value=['Costs',],
    options=['Gbytes', 'Costs',], size=2)

selectors = pn.Row(bucket_select, display_select, table_plot_select)
import matplotlib.pyplot as plt

def return_plot_table_please(bucket, plot):
    my_df = groom_df(df,bucket)
    print(plot)
    df_widget = pn.widgets.DataFrame(my_df, show_index=True, 
        fit_columns=True, row_height=23, name='Bucket Usage Table')
    iaxs = my_df.plot.bar(x='DirPrefix', y='Costs', title=f'BUCKET:{bucket}', width=500, height=400)
    
    costs_total = my_df.iloc[-1]['Costs']
    usage_guage.value = costs_total
    
    if 'Plot' in plot:
        return(iaxs)
    else:
        return(df_widget)
@pn.depends(bucket_select.param.value)
def refresh_plot_table(bucket_select):
    plot_v_table = table_plot_select.value
    return(return_plot_table_please(bucket_select, plot_v_table))
usage_guage = pn.indicators.Dial(name='Budget', value=900, bounds=(0, 1300), height=100, width=100, 
                            format='{value} dollars', 
                            colors = [(0.2, 'green'), (0.8, 'gold'), (1, 'red')],
                            margin=(100,10))
my_layout = pn.Column( 
    title,
    selectors,
    pn.Row(refresh_plot_table, usage_guage),
    '### the end'
)
my_layout.servable()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1343701399688958, 'fraction_numerical': 0.01275272161741835, 'mean_word_length': 3.6744186046511627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '250499', 'license': 'MIT', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1083, 'n_words': 234, 'path': '4_Jan_2022/Panel_Examples/3_AWS_S3_COST_APP_Cloud_Class_Demo.ipynb', 'repo_name': 'tonybutzer/teigen-lightning-talks', 'size': '3215'}