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')