-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can the gr.HTML onclick attribute call a Python function? #2914
Comments
Worst case, the |
If you want to execute a python function is response to a button click, then the builtin in |
@pngwn @abidlabs Can you please present an example of Also: splitting hairs here, but providing one interface inside |
Gradio isn't intended to be infinitely flexible, adding official APIs on top of things like HTML and Markdown that connect back to python is opening an enormous can of worms because it essentially provides infinite flexibility and removes many constraints that currently exist. You are just talking about button clicking in this case but we couldn't only support that, we would have to support any DOM event on any element or it wouldn't be internally consistent. This would just make Gradio a web framework like any other, which we have no desire to become. Theming (coming very soon) and custom components (coming soon) will be the official way to style things in a variety of ways and provide your own completely custom implementation when that isn't enough. |
@pngwn: I disagree about those specific decisions; that supporting Do you have a timeline for theming? And is there any way in the short term to make the buttons smaller? Thanks. 🙏 |
Hi @davidbernat, I concur with @pngwn's points about limiting the scope of Gradio's HTML component. In terms of your question about making the buttons smaller, you can apply CSS to any element using an approach like this: import gradio as gr
with gr.Blocks(css="#b {color:red}") as demo:
btn = gr.Button("run", elem_id="b")
demo.launch() |
Hi @abidlabs: thank you for clarifying and solidifying the (and your) Gradio position on this issue of JavaScript, Gradio, and Python. 🙏 As for the CSS: thank you for that example. I had not seen the Also: if you do create an email list for technical (engineering team) updates to Gradio, as opposed to product level updates, please sign me up. |
Sure thing @davidbernat. What do you mean by resizing the button? Do you mean the width of the button or something else? |
@abidlabs I mean resizing the button. Here is a common problem in Gradio. |
A couple of suggestions.
import gradio as gr
with gr.Blocks() as demo:
with gr.Row():
gr.Textbox()
gr.Button().style(full_width=False)
demo.launch() |
import gradio as gr
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(scale=3):
gr.Textbox()
with gr.Column(scale=1, min_width=100):
gr.Button()
demo.launch() |
@abidlabs Woohoo! Is this documented anywhere? If not in a public document, can you point to the line of code? Not surprisingly, many of your elements inherent from base classes, so features like |
Thank you, @abidlabs. Those parameters as you specify do render the widths within the column much better. May I ask a few follow-up questions?
|
The parameters are for columns, but you can put anything in a column including a single FileUpload box
That is not possible right now, but perhaps something we should enable. Feel free to open an issue with more details about why this would be helpful
Can you elaborate more on what you mean by the fill? Btw for questions like these, it would be ideal if you could use the GitHub forums or the Discord, as these issues are designed for bugs / new feature requests. |
This issue, #2520, discusses a bug relevant to render HTML Buttons through the
gr.HTML()
function. Later in that issue, one of the comments uses the Buttononclick="alert('Hello world!')"
attribute to execute a JavaScript function. Is it possible to configure theonclick
attribute ofgr.HTML()
element to execute a Python function instead?The text was updated successfully, but these errors were encountered: