Spaces:
Sleeping
Sleeping
sedrick-keh-tri
commited on
Commit
·
a6ad59e
1
Parent(s):
bec170a
fix scrolling
Browse files
app.py
CHANGED
|
@@ -111,12 +111,8 @@ def get_table_info(table_name):
|
|
| 111 |
|
| 112 |
return info
|
| 113 |
|
| 114 |
-
#
|
| 115 |
-
|
| 116 |
-
"""Generate CSS with custom column widths based on column_widths config"""
|
| 117 |
-
|
| 118 |
-
# Base CSS
|
| 119 |
-
base_css = """
|
| 120 |
/* Default table cell styling */
|
| 121 |
table td,
|
| 122 |
table th {
|
|
@@ -129,14 +125,22 @@ def generate_css():
|
|
| 129 |
padding: 4px 8px !important;
|
| 130 |
}
|
| 131 |
|
| 132 |
-
/* Make table container scrollable */
|
| 133 |
-
.dataframe
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
| 136 |
max-height: 600px !important;
|
| 137 |
overflow: auto !important;
|
| 138 |
}
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
/* Ensure table uses fixed layout */
|
| 141 |
table {
|
| 142 |
table-layout: fixed !important;
|
|
@@ -152,29 +156,6 @@ def generate_css():
|
|
| 152 |
}
|
| 153 |
"""
|
| 154 |
|
| 155 |
-
# Add custom column widths using nth-child selectors
|
| 156 |
-
custom_css = ""
|
| 157 |
-
if table_data and table_names:
|
| 158 |
-
for table_name in table_names:
|
| 159 |
-
if table_name in table_data:
|
| 160 |
-
df = table_data[table_name]
|
| 161 |
-
for idx, col_name in enumerate(df.columns):
|
| 162 |
-
if col_name in column_widths:
|
| 163 |
-
width = column_widths[col_name]
|
| 164 |
-
# nth-child is 1-indexed
|
| 165 |
-
custom_css += f"""
|
| 166 |
-
table td:nth-child({idx + 1}),
|
| 167 |
-
table th:nth-child({idx + 1}) {{
|
| 168 |
-
width: {width}px !important;
|
| 169 |
-
min-width: {width}px !important;
|
| 170 |
-
max-width: {width}px !important;
|
| 171 |
-
}}
|
| 172 |
-
"""
|
| 173 |
-
|
| 174 |
-
return base_css + custom_css
|
| 175 |
-
|
| 176 |
-
css = generate_css()
|
| 177 |
-
|
| 178 |
with gr.Blocks(title="VLA Foundry Database Viewer", css=css) as demo:
|
| 179 |
gr.Markdown("# 🤖 VLA Foundry Database Viewer")
|
| 180 |
gr.Markdown("Explore the VLA Foundry database with searchable, filterable, and sortable tables.")
|
|
@@ -223,12 +204,21 @@ with gr.Blocks(title="VLA Foundry Database Viewer", css=css) as demo:
|
|
| 223 |
)
|
| 224 |
clear_btn = gr.Button("Clear Filters", scale=1)
|
| 225 |
|
| 226 |
-
# Data table
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
data_table = gr.Dataframe(
|
| 228 |
-
value=
|
| 229 |
label="Table Data",
|
| 230 |
interactive=True,
|
| 231 |
-
wrap=False
|
|
|
|
| 232 |
)
|
| 233 |
|
| 234 |
# Event handlers
|
|
|
|
| 111 |
|
| 112 |
return info
|
| 113 |
|
| 114 |
+
# Create Gradio interface with CSS
|
| 115 |
+
css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
/* Default table cell styling */
|
| 117 |
table td,
|
| 118 |
table th {
|
|
|
|
| 125 |
padding: 4px 8px !important;
|
| 126 |
}
|
| 127 |
|
| 128 |
+
/* Make ONLY the table container scrollable, not parent divs */
|
| 129 |
+
.dataframe {
|
| 130 |
+
max-height: 600px !important;
|
| 131 |
+
overflow: auto !important;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
.table-wrap {
|
| 135 |
max-height: 600px !important;
|
| 136 |
overflow: auto !important;
|
| 137 |
}
|
| 138 |
|
| 139 |
+
/* Remove overflow from parent containers */
|
| 140 |
+
div[data-testid="data-table"] {
|
| 141 |
+
overflow: visible !important;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
/* Ensure table uses fixed layout */
|
| 145 |
table {
|
| 146 |
table-layout: fixed !important;
|
|
|
|
| 156 |
}
|
| 157 |
"""
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
with gr.Blocks(title="VLA Foundry Database Viewer", css=css) as demo:
|
| 160 |
gr.Markdown("# 🤖 VLA Foundry Database Viewer")
|
| 161 |
gr.Markdown("Explore the VLA Foundry database with searchable, filterable, and sortable tables.")
|
|
|
|
| 204 |
)
|
| 205 |
clear_btn = gr.Button("Clear Filters", scale=1)
|
| 206 |
|
| 207 |
+
# Data table with custom column widths
|
| 208 |
+
initial_df = table_data[table_names[0]] if table_names else pd.DataFrame()
|
| 209 |
+
|
| 210 |
+
# Build column_widths list based on the column_widths config
|
| 211 |
+
col_width_list = []
|
| 212 |
+
if not initial_df.empty:
|
| 213 |
+
for col in initial_df.columns:
|
| 214 |
+
col_width_list.append(column_widths.get(col, 300))
|
| 215 |
+
|
| 216 |
data_table = gr.Dataframe(
|
| 217 |
+
value=initial_df,
|
| 218 |
label="Table Data",
|
| 219 |
interactive=True,
|
| 220 |
+
wrap=False,
|
| 221 |
+
column_widths=col_width_list if col_width_list else None
|
| 222 |
)
|
| 223 |
|
| 224 |
# Event handlers
|