To upload files, please first save the app
import streamlit as st
import streamlit.components.v1 as components
# HTML and JavaScript for the Flatpickr date picker with Monday as the first day
flatpickr_html = """
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<div>
<input type="text" id="date-picker" placeholder="Select a date">
<input type="hidden" id="selected-date" name="selected-date">
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
flatpickr("#date-picker", {
"locale": {
"firstDayOfWeek": 1 // Monday as the first day
},
dateFormat: "Y-m-d",
onChange: function(selectedDates, dateStr, instance) {
document.getElementById("selected-date").value = dateStr;
document.getElementById("selected-date").dispatchEvent(new Event("input", { bubbles: true }));
}
});
});
</script>
"""
# Display the HTML with the Flatpickr date picker
components.html(flatpickr_html, height=350)
# Capture the selected date using Streamlit's hidden input
selected_date = st.text_input("Selected date", key="selected_date")
# Display the selected date if it has been set
if selected_date:
st.write("You selected:", selected_date)
else:
st.write("Please select a date.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?