panel_example7 / app.py
EasySci's picture
Update app.py
8dd8976
raw
history blame
5.23 kB
import panel as pn
# Create buttons for the toggleable sidebar
button1 = pn.widgets.Button(icon='home', name="Home", icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140)
button2 = pn.widgets.Button(icon='file-analytics', name='My papers', icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140)
button3 = pn.widgets.Button(icon='settings', icon_size='1.5em', name='Settings', button_type = 'primary', button_style = 'outline', width = 140)
# Create a column layout for the buttons inside the toggleable sidebar
buttons = pn.Column(button1, button2, button3 , css_classes=['hidden'])
instructions = """
## Modified-gravity wormholes without exotic matter
### Tiberiu Harko, Francisco S. N. Lobo, M. K. Mak, and Sergey V. Sushkov
A fundamental ingredient in wormhole physics is the flaring-out condition at the throat which,
in classical general relativity, entails the violation of the null energy condition. In this work, we
present the most general conditions.....
"""
instructions2 = """
## Viability of Bouncing Cosmology in Energy-Momentum-Squared
### Ahmed H. Barbar, Adel M. Awad, and Mohammad T. AlFiky
We analyze the early-time isotropic cosmology in the so-called energy-momentum-squared gravity
(EMSG). In this theory, a FORMATAÇAO term is added to the Einstein-Hilbert action, which has been
shown to replace the initial singularity by a regular bounce. We show that this is not the case,
and the bouncing solution obtained does.....
"""
text = pn.pane.Markdown(instructions)
text2 = pn.pane.Markdown(instructions2)
# List to store the entered options
entered_options = [
"Astrophysics",
"Condensed Matter",
"Mathematical Physics",
"Nuclear Experiment"
]
# Create buttons for the header
header_buttons = pn.Row(sizing_mode='stretch_width', css_classes=['header-buttons'])
# "+" button to trigger the addition to the header
add_to_header_button = pn.widgets.Button(name="", icon='search', icon_size='1.5em', button_style = 'outline',button_type = 'light')
# List to store the names of buttons to be added to the header
buttons_to_add = []
# Callback for adding selected options to the list
def add_to_header(event):
selected_options = filter_list.value
if selected_options:
for option in selected_options:
if option not in buttons_to_add: # Check if option is already in header
buttons_to_add.append(option) # Add to header if not already present
filter_list.value = [] # Clear the selected options after adding them to the header
update_header() # Update the header after adding options
add_to_header_button.on_click(add_to_header)
# Function to update the header layout with the newly created buttons
def update_header():
header_buttons.clear() # Clear the existing buttons
for button_name in buttons_to_add:
header_button = pn.widgets.Button(name=button_name, button_type = 'primary', button_style = 'outline')
header_button.on_click(remove_from_header) # Add callback to remove the header button
header_buttons.append(header_button)
print(buttons_to_add, flush = True)
# Update the filter list options to exclude buttons that are already in the header
filter_list.options = [option for option in entered_options if option not in buttons_to_add]
# MultiChoice widget to display the filter options with delete buttons
filter_list = pn.widgets.MultiChoice(
name='',
value=[],
options=entered_options,
margin=(20, 10),
sizing_mode='fixed',
solid=False,
styles={'background': '#f0f0f0'},
placeholder="Search Topics"
)
# Callback to remove the clicked header button
def remove_from_header(event):
button = event.obj # Get the clicked button
if button.name in buttons_to_add:
buttons_to_add.remove(button.name) # Remove from the header buttons list
filter_list.options.append(button.name) # Add back to the filter list options
update_header() # Update the header and filter list
# Layout using Template
template = pn.template.FastListTemplate(
title="EasySciRead",
header=[pn.Row(header_buttons, width=800, sizing_mode='fixed'), pn.Row(filter_list, width=250), pn.Row(add_to_header_button, width=55)],
main=[
# First row of the grid
pn.Row(pn.pane.Markdown("# Cosmology"),
pn.Column(text, text2, sizing_mode='stretch_width'),
pn.Column(text2, text, sizing_mode='stretch_width'),
sizing_mode='stretch_width',
),
# Second row of the grid
pn.Row(pn.pane.Markdown("# Astrophysics"),
pn.Column(text, text2, sizing_mode='stretch_width'),
sizing_mode='stretch_width',
),
],
sidebar=[buttons],
accent_base_color="#88d8b0",
header_background="#FFFFFF",
header_color="#000000",
text_align='center',
sidebar_width=150
)
def run_code(event):
# Add your desired Python code here
# For example, let's print "Hello, Panel!" when the button is clicked
print("Hello, Panel!", flush = True)
# Attach the function to the button's on_click event
button3.on_click(run_code)
# Run the app
template.servable()