Spaces:
Build error
Build error
Kelbec
commited on
Commit
•
1781019
1
Parent(s):
00a88d2
validation on file selection
Browse files- pages/01_dcascade.py +29 -12
pages/01_dcascade.py
CHANGED
@@ -152,6 +152,8 @@ def Page():
|
|
152 |
filename, set_filename = solara.use_state("")
|
153 |
river_filename, set_river_filename = solara.use_state("")
|
154 |
q_filename, set_q_filename = solara.use_state("")
|
|
|
|
|
155 |
# removed_data, set_removed = solara.use_state("")
|
156 |
size, set_size = solara.use_state(0)
|
157 |
file_browser, set_file_browser = solara.use_state(cast(Optional[Path], None))
|
@@ -175,18 +177,22 @@ def Page():
|
|
175 |
|
176 |
def open_river_file():
|
177 |
if file_browser:
|
178 |
-
|
179 |
-
file_path
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
|
|
184 |
|
185 |
def open_q_file():
|
186 |
if file_browser:
|
187 |
-
|
188 |
-
file_path
|
189 |
-
|
|
|
|
|
|
|
190 |
|
191 |
def remove_data():
|
192 |
for file in os.listdir(os.getcwd()+"/public"):
|
@@ -252,12 +258,23 @@ def Page():
|
|
252 |
solara.Button("Select Q file",
|
253 |
color="primary",
|
254 |
on_click=open_q_file)
|
255 |
-
|
256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
solara.FileBrowser(
|
259 |
can_select=False,
|
260 |
-
on_file_open=set_file_browser
|
|
|
261 |
)
|
262 |
solara.Markdown("#### Run model")
|
263 |
with solara.ColumnsResponsive(3, large=6):
|
|
|
152 |
filename, set_filename = solara.use_state("")
|
153 |
river_filename, set_river_filename = solara.use_state("")
|
154 |
q_filename, set_q_filename = solara.use_state("")
|
155 |
+
error_select_csv, set_error_select_csv = solara.use_state("")
|
156 |
+
error_select_shp, set_error_select_shp = solara.use_state("")
|
157 |
# removed_data, set_removed = solara.use_state("")
|
158 |
size, set_size = solara.use_state(0)
|
159 |
file_browser, set_file_browser = solara.use_state(cast(Optional[Path], None))
|
|
|
177 |
|
178 |
def open_river_file():
|
179 |
if file_browser:
|
180 |
+
file_path = os.path.join(os.getcwd(),file_browser)
|
181 |
+
if file_path.endswith(".shp"):
|
182 |
+
set_river_filename(file_path)
|
183 |
+
set_error_select_shp(False)
|
184 |
+
else:
|
185 |
+
set_error_select_shp(True)
|
186 |
+
|
187 |
|
188 |
def open_q_file():
|
189 |
if file_browser:
|
190 |
+
file_path = os.path.join(os.getcwd(),file_browser)
|
191 |
+
if file_path.endswith(".csv"):
|
192 |
+
set_q_filename(file_path)
|
193 |
+
set_error_select_csv(False)
|
194 |
+
else:
|
195 |
+
set_error_select_csv(True)
|
196 |
|
197 |
def remove_data():
|
198 |
for file in os.listdir(os.getcwd()+"/public"):
|
|
|
258 |
solara.Button("Select Q file",
|
259 |
color="primary",
|
260 |
on_click=open_q_file)
|
261 |
+
if error_select_csv:
|
262 |
+
solara.Warning(f"Q file must be csv",
|
263 |
+
text=True,
|
264 |
+
dense=True,
|
265 |
+
icon=True,
|
266 |
+
)
|
267 |
+
if error_select_shp:
|
268 |
+
solara.Warning(f"River file must be shp",
|
269 |
+
text=True,
|
270 |
+
dense=True,
|
271 |
+
icon=True,
|
272 |
+
)
|
273 |
|
274 |
solara.FileBrowser(
|
275 |
can_select=False,
|
276 |
+
on_file_open=set_file_browser,
|
277 |
+
directory="./public"
|
278 |
)
|
279 |
solara.Markdown("#### Run model")
|
280 |
with solara.ColumnsResponsive(3, large=6):
|