Brian
Brian
SSolara
Created by Brian on 2/20/2025 in #questions-issues
InputDate with buttons
Hi there, I'm trying to replicate the "more advanced" example here: https://solara.dev/documentation/components/lab/input_date#a-more-advanced-example but with the InputDate component (so only one date). I want the menu to have a "Select" button (and maybe also a "Cancel" button) so that the value isn't automatically picked when the user clicks on a date. I'm having issues getting it to work though. Even though I am passing the open_value parameter (because I want to control when the menu closes), the menu closes whenever I click on a date. The example from the docs does work for me, though I don't understand how. (My guess is that it's because that example is using an InputDateRange, but it does not allow the user to ever pick the second date because it's set automatically based on the stay_length...?) Here's my simple example (which does not work):
import solara
import solara.lab
import datetime as dt


@solara.component
def Page():
date_picker_is_open = solara.use_reactive(False)

selected_date = solara.use_reactive(dt.date.today().replace(day=1))
prior_selected_date = solara.use_previous(selected_date.value)

def on_date_selected():
# Do some stuff here
date_picker_is_open.set(False)

def on_cancel_clicked():
selected_date.set(prior_selected_date)

with solara.Column(style="width: 400px;"):
with solara.lab.InputDate(
selected_date,
open_value=date_picker_is_open,
date_picker_type="month",
date_format="%b %Y",
):
with solara.Row(justify="end", style="width: 100%;"):
solara.Button(
label="Cancel",
on_click=on_cancel_clicked,
)
solara.Button(
label="Select",
color="primary",
on_click=on_date_selected,
)

Page()
import solara
import solara.lab
import datetime as dt


@solara.component
def Page():
date_picker_is_open = solara.use_reactive(False)

selected_date = solara.use_reactive(dt.date.today().replace(day=1))
prior_selected_date = solara.use_previous(selected_date.value)

def on_date_selected():
# Do some stuff here
date_picker_is_open.set(False)

def on_cancel_clicked():
selected_date.set(prior_selected_date)

with solara.Column(style="width: 400px;"):
with solara.lab.InputDate(
selected_date,
open_value=date_picker_is_open,
date_picker_type="month",
date_format="%b %Y",
):
with solara.Row(justify="end", style="width: 100%;"):
solara.Button(
label="Cancel",
on_click=on_cancel_clicked,
)
solara.Button(
label="Select",
color="primary",
on_click=on_date_selected,
)

Page()
12 replies
SSolara
Created by Brian on 11/20/2024 in #questions-issues
Localization of datetime
Hi there! I am trying to figure out how to localize a datetime object in my Solara application. I want to show a banner like:
solara.Success(f"Saved at {some_datetime}.")
solara.Success(f"Saved at {some_datetime}.")
Where some_datetime would be a datetime.datetime object that I would retrieve from a database. The datetime value would be saved in UTC, but I'd like to format it (and shift the timezone) to the user's locale. I know I can get the user's language preference from solara.lab.headers.value["accept-language"] but this doesn't give me the timezone info. I think this should be possible with JavaScript (with something like toLocaleDateString()), but I don't know how to run JavaScript in Solara. (I was poking around with solara.HTML, but coudn't quite figure it out and don't know how to insert that into the solara.Success message.) Any help or suggestions would be appreciated!
4 replies
SSolara
Created by Brian on 8/5/2024 in #questions-issues
Creating a form when I don't know how many user inputs there will be at development time
9 replies
SSolara
Created by Brian on 4/18/2024 in #questions-issues
PermissionError for nbextensions on startup with v1.29+
hi all, i've been trying out solara for the past month or so. i was using v1.28 with no issues. today i tried upgrading and i've been having trouble getting things running on any higher version. i know that there were significant changes to the packaging starting with v1.31, but at this point i can't even upgrade to v1.29. i'm getting a PermissionError on startup:
PermissionError: [Errno 13] Permission denied: '/usr/local/share/jupyter/nbextensions/jupyter-vuetify/extension.js'
PermissionError: [Errno 13] Permission denied: '/usr/local/share/jupyter/nbextensions/jupyter-vuetify/extension.js'
i'm creating a multi-page app, and i'm pip-installing in editable mode (since i'm actively developing) from a pyproject.toml file. i have an environment with solara v1.28.0 and one with v1.29.1. it works with v1.28, but i get the error with v1.29 (and v1.30). any help would be appreciated!
9 replies