put all visual components in one file
Browse files- visual_components.py +60 -0
visual_components.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit.components.v1 as components
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def create_data_input_table(datapoint, col_names):
|
| 7 |
+
st.subheader("Flagged Transaction:")
|
| 8 |
+
data = datapoint.iloc[0].tolist()
|
| 9 |
+
data[7:12] = [bool(value) for value in data[7:12]]
|
| 10 |
+
df = pd.DataFrame({"Feature name": col_names, "Value": data })
|
| 11 |
+
st.dataframe(df, hide_index=True, width=450, height=35*len(df)+38)
|
| 12 |
+
|
| 13 |
+
# Create a function to generate a table
|
| 14 |
+
def create_table(texts, values, title):
|
| 15 |
+
# TODO: change color dataframe header -> tried many different options but none worked see below
|
| 16 |
+
# header_style = '''s
|
| 17 |
+
# <style>
|
| 18 |
+
# th{
|
| 19 |
+
# background-color: #00052D;
|
| 20 |
+
# }
|
| 21 |
+
# </style>
|
| 22 |
+
# '''
|
| 23 |
+
df = pd.DataFrame({"Feature Explanation": texts, 'Value': values})
|
| 24 |
+
# df = df.style.set_properties(**{
|
| 25 |
+
# 'selector': 'th',
|
| 26 |
+
# 'props': [
|
| 27 |
+
# ('background-color', 'black'),
|
| 28 |
+
# ('color', 'cyan')]
|
| 29 |
+
# })
|
| 30 |
+
# df = df.style.set_properties(**{'background-color': 'black',
|
| 31 |
+
# 'color': 'green'})
|
| 32 |
+
|
| 33 |
+
st.markdown(f'#### {title}') # Markdown for styling
|
| 34 |
+
headers = {
|
| 35 |
+
'selector': 'th',
|
| 36 |
+
'props': 'background-color' '#67c5a4'#'background-color: #000066; color: white;'
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
df = df.style.set_table_styles({
|
| 40 |
+
('Feature Explanation', 'Value'): [{'selector': 'th', 'props': 'border-left: 1px solid white'},
|
| 41 |
+
{'selector': 'td', 'props': 'border-left: 1px solid #000066'}]
|
| 42 |
+
}, axis=0)
|
| 43 |
+
|
| 44 |
+
# df.style.set_table_styles([headers])
|
| 45 |
+
st.dataframe(df, hide_index=True, width=450) # Display a simple table
|
| 46 |
+
# st.markdown(header_style, unsafe_allow_html=True)
|
| 47 |
+
|
| 48 |
+
def ChangeButtonColour(widget_label, font_color, background_color='transparent'):
|
| 49 |
+
htmlstr = f"""
|
| 50 |
+
<script>
|
| 51 |
+
var elements = window.parent.document.querySelectorAll('button');
|
| 52 |
+
for (var i = 0; i < elements.length; ++i) {{
|
| 53 |
+
if (elements[i].innerText == '{widget_label}') {{
|
| 54 |
+
elements[i].style.color ='{font_color}';
|
| 55 |
+
elements[i].style.background = '{background_color}'
|
| 56 |
+
}}
|
| 57 |
+
}}
|
| 58 |
+
</script>
|
| 59 |
+
"""
|
| 60 |
+
components.html(f"{htmlstr}", height=0, width=0)
|