bluenevus commited on
Commit
cfad611
·
verified ·
1 Parent(s): 1e9ab38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -17
app.py CHANGED
@@ -16,7 +16,10 @@ JSON_FILE = 'app.json'
16
  def load_links():
17
  if os.path.exists(JSON_FILE):
18
  with open(JSON_FILE, 'r') as f:
19
- return json.load(f)
 
 
 
20
  return []
21
 
22
  def generate_url_list(links):
@@ -47,8 +50,7 @@ app.layout = dbc.Container([
47
  style={'width': '100%', 'height': '800px'},
48
  sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-downloads",
49
  allow="fullscreen; geolocation; microphone; camera; midi; encrypted-media; autoplay",
50
- referrerPolicy="no-referrer",
51
- key='' # Add this line
52
  )
53
  ], width=10, className="bg-white")
54
  ])
@@ -63,34 +65,35 @@ def update_url_list(_):
63
  url_list = generate_url_list(links)
64
  return url_list
65
 
66
- @callback(
67
- Output('content-iframe', 'src'),
68
- Input({'type': 'url-button', 'index': dash.ALL}, 'n_clicks'),
69
- prevent_initial_call=True
70
- )
71
  @callback(
72
  [Output('content-iframe', 'src'),
73
- Output('content-iframe', 'key')], # Add a key output to force refresh
74
- Input({'type': 'url-button', 'index': dash.ALL}, 'n_clicks'),
 
75
  prevent_initial_call=True
76
  )
77
- def update_iframe(*n_clicks):
78
  ctx = dash.callback_context
79
  if not ctx.triggered:
80
- print("No button clicked")
81
  return dash.no_update, dash.no_update
 
 
82
 
83
- button_id = ctx.triggered[0]['prop_id'].split('.')[0]
84
- clicked_id = eval(button_id)['index']
85
- print(f"Button clicked: {clicked_id}")
 
 
 
86
 
87
  links = load_links()
88
  for link in links:
89
- if link['id'] == clicked_id:
90
  url = link['url']
91
  print(f"Loading URL: {url}")
92
  return url, url # Return URL for both src and key
93
-
94
  print("No matching URL found")
95
  return dash.no_update, dash.no_update
96
 
 
16
  def load_links():
17
  if os.path.exists(JSON_FILE):
18
  with open(JSON_FILE, 'r') as f:
19
+ links = json.load(f)
20
+ print(f"Loaded links: {links}") # Debug print
21
+ return links
22
+ print("JSON file not found") # Debug print
23
  return []
24
 
25
  def generate_url_list(links):
 
50
  style={'width': '100%', 'height': '800px'},
51
  sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-downloads",
52
  allow="fullscreen; geolocation; microphone; camera; midi; encrypted-media; autoplay",
53
+ referrerPolicy="no-referrer"
 
54
  )
55
  ], width=10, className="bg-white")
56
  ])
 
65
  url_list = generate_url_list(links)
66
  return url_list
67
 
 
 
 
 
 
68
  @callback(
69
  [Output('content-iframe', 'src'),
70
+ Output('content-iframe', 'key')],
71
+ [Input('url-list', 'children'),
72
+ Input({'type': 'url-button', 'index': dash.ALL}, 'n_clicks')],
73
  prevent_initial_call=True
74
  )
75
+ def update_iframe(url_list, *n_clicks):
76
  ctx = dash.callback_context
77
  if not ctx.triggered:
78
+ print("No trigger")
79
  return dash.no_update, dash.no_update
80
+
81
+ trigger_id = ctx.triggered[0]['prop_id'].split('.')[0]
82
 
83
+ if trigger_id == 'url-list':
84
+ print("URL list updated, not changing iframe")
85
+ return dash.no_update, dash.no_update
86
+
87
+ button_id = eval(trigger_id)['index']
88
+ print(f"Button clicked: {button_id}")
89
 
90
  links = load_links()
91
  for link in links:
92
+ if link['id'] == button_id:
93
  url = link['url']
94
  print(f"Loading URL: {url}")
95
  return url, url # Return URL for both src and key
96
+
97
  print("No matching URL found")
98
  return dash.no_update, dash.no_update
99