icecream4
icecream4
SSolara
Created by icecream4 on 5/14/2024 in #questions-issues
Run JS script
In my application I use solara as an iframe and sometimes I need to send information to the front. I need send info after clicking the buttons. I have several buttons after some of them work, it is necessary for an alert message or a base64 image to be sent to the front. My sending function looks like this:
def sendMessageToFront(msg):
jsn = json.dumps(msg.value)

custom_js = f"""
window.parent.postMessage({{
data: {jsn},
type: "ipynb",
key: "test"
}}, '*');
"""
solara.HTML(tag="script", unsafe_innerHTML=custom_js)
def sendMessageToFront(msg):
jsn = json.dumps(msg.value)

custom_js = f"""
window.parent.postMessage({{
data: {jsn},
type: "ipynb",
key: "test"
}}, '*');
"""
solara.HTML(tag="script", unsafe_innerHTML=custom_js)
And I don’t know how to properly integrate it into this scheme:
import solara

message_dict = solara.reactive({})

def on_click_1():
...
message_dict.set({"alertMessage": "CLICK 1"})

def on_click_2():
...
message_dict.set("imageLink": f'data:image/png;base64,{img_b64}')

@solara.component
def Page():
solara.Button(label="CLICK 1", on_click=on_click_1)
solara.Button(label="CLICK 2", on_click=on_click_2)

Page()
import solara

message_dict = solara.reactive({})

def on_click_1():
...
message_dict.set({"alertMessage": "CLICK 1"})

def on_click_2():
...
message_dict.set("imageLink": f'data:image/png;base64,{img_b64}')

@solara.component
def Page():
solara.Button(label="CLICK 1", on_click=on_click_1)
solara.Button(label="CLICK 2", on_click=on_click_2)

Page()
4 replies
SSolara
Created by icecream4 on 4/25/2024 in #questions-issues
Initializing function.
Please help me make an initializing function. I'm using the solara.use_router().search function to get a data. For example, I use this data as values in solara.Select. I have a problem that after changing the value in select and clicking the button, the value returns to the one I set during initialization. Therefore, I want to write a function that will be called only once when first launched, receive data, write it to several solara.reactive (I have a lot of them), and then not run.
9 replies
SSolara
Created by icecream4 on 4/18/2024 in #questions-issues
Image Select
Hi all. Can you help me. I'm trying to make an image selector, like the one made here by https://github.com/jrieke/streamlit-image-select for streamlit. I tried to do this using ToggleButtonsSingle, it worked for me, but all the buttons with pictures end up in one line, and I can have a lot of pictures, I tried to add GridFixed, but now everything crashes because it can’t find the value correctly.
4 replies