Py.Cafe

sh.mukherjee+py/

plotly-central-bank-policy-rates

Analysis of Central Bank Policy Rates

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import plotly.express as px
import pandas as pd
from shiny.express import input, render, ui
from shinywidgets import render_plotly
#from data import df

urls = ["https://stats.bis.org/api/v2/data/dataflow/BIS/WS_CBPOL/1.0/M.AU+CN+GB+IN+JP+US+XM?format=csv"]

df = pd.concat([pd.read_csv(url) for url in urls])

start="2014-09-30"
end="2024-08-31"

ui.page_opts(title="Central Bank Policy Rates", fillable=True)
with ui.sidebar():
    #ui.input_selectize("ticker", "Select Stocks", choices=stocks, selected="AAPL")
    ui.input_date_range("dates", "Select dates", start=start, end=end)

@reactive.calc
def filter_df():
    dates = input.dates()
    return df[(df['TIME_PERIOD:Period'] >= dates[0]) & (df['TIME_PERIOD:Period'] <= dates[1])]

with ui.layout_columns():
    @render.data_frame
    def trim_df():
        x = filter_df()[["REF_AREA:Reference area","TIME_PERIOD:Period","OBS_VALUE:Value"]]
        return x

    @render_plotly
    def plot1():
        return px.line(trim_df(), x="TIME_PERIOD:Period", y="OBS_VALUE:Value", color='REF_AREA:Reference area')