awacke1 commited on
Commit
6bfc014
·
verified ·
1 Parent(s): 83d0bb4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -29
app.py CHANGED
@@ -101,53 +101,63 @@ def save_votes(votes):
101
  def main():
102
  st.set_page_config(layout="wide")
103
 
104
- if 'current_url' not in st.session_state:
105
- st.session_state.current_url = None
106
 
107
  votes = load_votes()
108
 
109
  col1, col2 = st.columns([1, 2])
110
 
111
  with col1:
112
- items = [{"url": url, "name": url.split('/')[-1],
113
- "emoji": get_emoji(url.split('/')[-1]),
114
- "votes": votes[url]} for url in urls]
 
 
 
 
 
 
115
  items.sort(key=lambda x: (-x["votes"], x["name"]))
116
 
117
  button_cols = st.columns(2)
118
  for i, item in enumerate(items):
119
  with button_cols[i % 2]:
120
- if st.button(f"{item['emoji']} {item['name']}", key=item['url']):
121
- votes[item['url']] += 1
122
  save_votes(votes)
123
- st.session_state.current_url = item['url']
124
- st.rerun()
125
  st.write(f"Votes: {item['votes']}")
126
 
127
  with col2:
128
- if st.session_state.current_url:
129
- html_string = f"""
130
- <div style="width:100%; height:800px; overflow:hidden;">
131
- <iframe src="{st.session_state.current_url}"
132
- width="100%"
133
- height="100%"
134
- frameborder="0"
135
- scrolling="yes"
136
- style="border: 1px solid #ddd;">
137
- </iframe>
138
- </div>
139
- """
140
- st.components.v1.html(html_string, height=800)
 
 
141
  else:
142
- st.info("Select an app to view")
143
 
144
  if any(votes.values()):
145
  with col1:
146
- df = pd.DataFrame([
147
- {'name': i["name"], 'votes': i["votes"]}
148
- for i in items if votes[i["url"]] > 0
149
- ])
150
- st.bar_chart(df.set_index('name'))
 
 
151
 
152
  if __name__ == "__main__":
153
- main()
 
101
  def main():
102
  st.set_page_config(layout="wide")
103
 
104
+ if "selected_url" not in st.session_state:
105
+ st.session_state.selected_url = None
106
 
107
  votes = load_votes()
108
 
109
  col1, col2 = st.columns([1, 2])
110
 
111
  with col1:
112
+ items = [
113
+ {
114
+ "url": url,
115
+ "name": url.split("/")[-1],
116
+ "emoji": get_emoji(url.split("/")[-1]),
117
+ "votes": votes[url],
118
+ }
119
+ for url in urls
120
+ ]
121
  items.sort(key=lambda x: (-x["votes"], x["name"]))
122
 
123
  button_cols = st.columns(2)
124
  for i, item in enumerate(items):
125
  with button_cols[i % 2]:
126
+ if st.button(f"{item['emoji']} {item['name']}", key=item["url"]):
127
+ votes[item["url"]] += 1
128
  save_votes(votes)
129
+ st.session_state.selected_url = item["url"]
130
+ st.experimental_rerun()
131
  st.write(f"Votes: {item['votes']}")
132
 
133
  with col2:
134
+ if "selected_url" in st.session_state and st.session_state.selected_url:
135
+ selected_url = st.session_state.selected_url
136
+ st.info(f"You selected: {selected_url}")
137
+
138
+ # Open the selected URL in a new browser tab or window
139
+ st.markdown(
140
+ f"""
141
+ <a href="{selected_url}" target="_blank" style="text-decoration: none;">
142
+ <button style="padding: 10px; background-color: #4CAF50; color: white; border: none; cursor: pointer;">
143
+ Open in New Tab
144
+ </button>
145
+ </a>
146
+ """,
147
+ unsafe_allow_html=True,
148
+ )
149
  else:
150
+ st.info("Select a space from the list on the left to view details.")
151
 
152
  if any(votes.values()):
153
  with col1:
154
+ df = pd.DataFrame(
155
+ [
156
+ {"name": i["name"], "votes": i["votes"]}
157
+ for i in items if votes[i["url"]] > 0
158
+ ]
159
+ )
160
+ st.bar_chart(df.set_index("name"))
161
 
162
  if __name__ == "__main__":
163
+ main()