Update utils/ui_helper.py
Browse files- utils/ui_helper.py +19 -2
utils/ui_helper.py
CHANGED
@@ -36,6 +36,7 @@ def main_algo_trader():
|
|
36 |
],
|
37 |
)
|
38 |
top_n = st.sidebar.number_input("Top n stocks", min_value=1, value=3)
|
|
|
39 |
|
40 |
# Process inputs
|
41 |
tickers_list = [ticker.strip() for ticker in tickers.split(",")]
|
@@ -64,6 +65,14 @@ def main_algo_trader():
|
|
64 |
]
|
65 |
df.index = pd.to_datetime(df.index, unit="ms")
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
# Create plot
|
68 |
fig = go.Figure()
|
69 |
fig.add_trace(
|
@@ -140,7 +149,15 @@ def main_algo_trader():
|
|
140 |
legend=dict(
|
141 |
orientation="h", x=0.5, y=-0.4, xanchor="center", yanchor="bottom"
|
142 |
),
|
143 |
-
height=
|
144 |
)
|
145 |
|
146 |
-
st.plotly_chart(fig, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
],
|
37 |
)
|
38 |
top_n = st.sidebar.number_input("Top n stocks", min_value=1, value=3)
|
39 |
+
height_of_graph = st.sidebar.number_input("Height of the plot", min_value=500, value=750)
|
40 |
|
41 |
# Process inputs
|
42 |
tickers_list = [ticker.strip() for ticker in tickers.split(",")]
|
|
|
65 |
]
|
66 |
df.index = pd.to_datetime(df.index, unit="ms")
|
67 |
|
68 |
+
# Create download file
|
69 |
+
@st.cache_data
|
70 |
+
def convert_df(df):
|
71 |
+
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
72 |
+
return df.to_csv().encode('utf-8')
|
73 |
+
|
74 |
+
csv = convert_df(df)
|
75 |
+
|
76 |
# Create plot
|
77 |
fig = go.Figure()
|
78 |
fig.add_trace(
|
|
|
149 |
legend=dict(
|
150 |
orientation="h", x=0.5, y=-0.4, xanchor="center", yanchor="bottom"
|
151 |
),
|
152 |
+
height=height_of_graph,
|
153 |
)
|
154 |
|
155 |
+
st.plotly_chart(fig, use_container_width=True)
|
156 |
+
|
157 |
+
# Download
|
158 |
+
st.download_button(
|
159 |
+
label="Download data as CSV",
|
160 |
+
data=csv,
|
161 |
+
file_name=f'history_{end_date}.csv',
|
162 |
+
mime='text/csv',
|
163 |
+
)
|