Is is possible i place a button or check box at any positon in the page?

Idea would be like
st.button(x = 100, y =200)
st.sidebar,button(x = 100, y =200)?

is it possible?
or any recommedation thanks

Hi @apex_yu,

First I would like to say, welcome to the Streamlit community!!! :partying_face: :partying_face: :partying_face: :tada: :tada: :tada: :tada: :tada:

For your question, without knowing exactly what your trying to achieve (a minimum working example is encouraged when posting a question!) I would say Streamlit doesn’t have this function. The button only takes maximum of 2 arguments, one of which is the name you want to have on the button. Check out our documentation for more details. So you can’t pass in an x and y coordinate that corresponds to a position on your app.

However, there are ways to adjust the layout of your app, and to be able to put buttons and widgets in specific areas of the page (just not with pixel level precision). Here are some options you may want to try:

import streamlit as st

# to make your app take up all the available space in the browser window
# (not just a single column)
st.set_page_config(layout='wide')

st.title("Title of an app")

# you can create columns to better manage the flow of your page
# this command makes 3 columns of equal width
col1, col2, col3 = st.beta_columns(3)

# this will put a button in the middle column
with col2:
    st.button("I am a button")

st.write("Now on to the other columns")

# this command will make 3 columns of unequal width
# first column is largest and 3x the size of the last,
# second column is 2x the size of the last
col4, col5, col6 = st.beta_columns([3,2,1])

# this will put a checkbox in the last column
col6.checkbox("I am a checkbox")

This looks like:

If you want to know more checkout the docs on laying out your app or this post on layout:

New layout options for Streamlit

Happy Streamlit-ing!
Marisa

1 Like

thanks you. I am using this new layout now,
however, the (Y co-coordndate or position ) cannot be organised
and i am assuming (for the row element its run according to python line of β€œrow” code to execute,

And can it be applied to the sidebar part?
thanks

Sorry I don’t know what you mean by this

Yes it can:

side_1, side_2 = st.sidebar.beta_columns(2)

with side_1:
    st.write('column 1')
    st.checkbox('checkbox in sidebar')

with side_2:
    st.write('column 2')

gives:

BUT:
The size of the sidebar does not change, if you try putting to many columns in it will be come crowded and confusing! I personally would only put columns in your sidebar if absolutely necessary and only ever put 2 columns in.

Happy Streamlit-ing!
Marisa

2 Likes