Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -4,10 +4,14 @@ import dash_bootstrap_components as dbc
|
|
4 |
import json
|
5 |
import os
|
6 |
import requests
|
7 |
-
from urllib3.exceptions import InsecureRequestWarning
|
8 |
|
9 |
# Disable SSL warnings
|
10 |
-
requests.packages.urllib3.disable_warnings(
|
|
|
|
|
|
|
|
|
11 |
|
12 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
13 |
|
@@ -49,6 +53,7 @@ app.layout = dbc.Container([
|
|
49 |
id='content-iframe',
|
50 |
style={'width': '100%', 'height': '800px'},
|
51 |
allow="*",
|
|
|
52 |
)
|
53 |
], width=10, className="bg-white")
|
54 |
])
|
@@ -64,36 +69,36 @@ def update_url_list(_):
|
|
64 |
return url_list
|
65 |
|
66 |
@callback(
|
67 |
-
|
68 |
-
|
69 |
-
[Input('url-list', 'children'),
|
70 |
-
Input({'type': 'url-button', 'index': dash.ALL}, 'n_clicks')],
|
71 |
prevent_initial_call=True
|
72 |
)
|
73 |
-
def update_iframe(
|
74 |
ctx = dash.callback_context
|
75 |
if not ctx.triggered:
|
76 |
-
print("No
|
77 |
-
return dash.no_update
|
78 |
-
|
79 |
-
trigger_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
button_id = eval(trigger_id)['index']
|
86 |
-
print(f"Button clicked: {button_id}")
|
87 |
|
88 |
links = load_links()
|
89 |
for link in links:
|
90 |
-
if link['id'] ==
|
91 |
url = link['url']
|
92 |
print(f"Loading URL: {url}")
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
print("No matching URL found")
|
96 |
-
return dash.no_update
|
97 |
|
98 |
if __name__ == '__main__':
|
99 |
print("Starting the Dash application...")
|
|
|
4 |
import json
|
5 |
import os
|
6 |
import requests
|
7 |
+
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
8 |
|
9 |
# Disable SSL warnings
|
10 |
+
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
11 |
+
|
12 |
+
# Create a session that ignores SSL verification
|
13 |
+
session = requests.Session()
|
14 |
+
session.verify = False
|
15 |
|
16 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
17 |
|
|
|
53 |
id='content-iframe',
|
54 |
style={'width': '100%', 'height': '800px'},
|
55 |
allow="*",
|
56 |
+
src=""
|
57 |
)
|
58 |
], width=10, className="bg-white")
|
59 |
])
|
|
|
69 |
return url_list
|
70 |
|
71 |
@callback(
|
72 |
+
Output('content-iframe', 'src'),
|
73 |
+
Input({'type': 'url-button', 'index': dash.ALL}, 'n_clicks'),
|
|
|
|
|
74 |
prevent_initial_call=True
|
75 |
)
|
76 |
+
def update_iframe(*n_clicks):
|
77 |
ctx = dash.callback_context
|
78 |
if not ctx.triggered:
|
79 |
+
print("No button clicked")
|
80 |
+
return dash.no_update
|
|
|
|
|
81 |
|
82 |
+
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
83 |
+
clicked_id = eval(button_id)['index']
|
84 |
+
print(f"Button clicked: {clicked_id}")
|
|
|
|
|
|
|
85 |
|
86 |
links = load_links()
|
87 |
for link in links:
|
88 |
+
if link['id'] == clicked_id:
|
89 |
url = link['url']
|
90 |
print(f"Loading URL: {url}")
|
91 |
+
try:
|
92 |
+
# Use the session to make a request, ignoring SSL errors
|
93 |
+
response = session.get(url, verify=False)
|
94 |
+
response.raise_for_status()
|
95 |
+
return url
|
96 |
+
except requests.exceptions.RequestException as e:
|
97 |
+
print(f"Error loading URL: {e}")
|
98 |
+
return url # Return the URL even if there's an error
|
99 |
+
|
100 |
print("No matching URL found")
|
101 |
+
return dash.no_update
|
102 |
|
103 |
if __name__ == '__main__':
|
104 |
print("Starting the Dash application...")
|