demo2 / app.py
KashyapiNagaHarshitha's picture
Update app.py
160dd0c verified
raw
history blame contribute delete
No virus
1.3 kB
import panel as pn
import pandas as pd
import os
pn.extension()
# Global variable to store the input value and the dataframe
stored_value = ""
df = None
# Define a callback to store the input value when the button is clicked
def store_value(event):
global stored_value, df
stored_value = text_input.value
# Path to the dataset
dataset_path = os.path.join("test_metadata/images", "Slide_B_DD1s1.one_1.tif.csv")
# Load the dataset
if os.path.exists(dataset_path):
df = pd.read_csv(dataset_path)
output_pane.object = f"Stored Value: {stored_value}\n\nDataFrame Head:\n{df.head().to_markdown(index=False)}"
else:
output_pane.object = f"Stored Value: {stored_value}\n\nError: File not found at {dataset_path}"
# Define the text input widget
text_input = pn.widgets.TextInput(
name="Input Text",
placeholder="Enter some text"
)
# Define the button widget
store_button = pn.widgets.Button(name='Store Value')
store_button.on_click(store_value)
# Define the output pane
output_pane = pn.pane.Markdown("Stored Value: ")
# Create a simple layout
layout = pn.Column(
pn.pane.Markdown("### Simple Panel App"),
text_input,
store_button,
output_pane,
sizing_mode="stretch_width"
)
# Serve the app
layout.servable()