I’m struggling to do some fairly rookie HTML stuff and searching for answers on this channel or trying to implement the answers I found on StackOverflow haven’t helped.
I have two problems. First, I have a local image that I want to display (st.image works, but doesn’t work because I can’t find where the media directory is hosted!
The more important problem is how do I render a text and image next to each other, like a logo and the name?
This is for an open source tool.
Thanks for providing an awesome tool to get started quickly.
Thanks for the response. I’m using the beta_columns, but it puts the text and the image far away from each other unless I manipulate the column widths a bit, but then it gets messed up if the display size changes.
Here is what I have now:
title_container = st.beta_container()
col1, col2 = st.beta_columns([1, 20])
image = Image.open('/home/ddutt/Pictures/Suzieq-logo-2.jpg')
with title_container:
with col1:
st.image(image, width=64)
with col2:
st.markdown('<h1 style="color: purple;">Suzieq</h1>',
unsafe_allow_html=True)
And the reason for wanting something else is because this separation between the logo and the name which looks perfect right now gets squashed together when I play with the screen size (tablet, smaller screen etc.)
So you want to keep some space between the logo and your name when you switch to a smaller screen device. Because when you switch (to a small screen) they are becoming squished together?
I trick I have used in the past to create a bit of space between columns is by actually making a middle column that I don’t put anything in. You have to play around with the sizing a bit but it does create space:
import streamlit as st
st.write("a logo and text next to eachother")
col1, mid, col2 = st.beta_columns([1,1,20])
with col1:
st.image('row_2_col_1.jpg', width=60)
with col2:
st.write('A Name')
gives:
because there is a column in the middle, when you switch to a smaller screen, it should preserve most of the spacing. The thing with columns in different screen sizes, is that they’re smart, and they automatically resize and redistribute based on the screen size. Checkout the blog post on layout options. So if the screen size gets too small, the other columns will get bumped below, as you can see in the gif on the blog.
Hope this proves helpful!
Happy Streamlit-ing!
Marisa
Ahh interesting. If you see my code, I had tried something like what you had suggested, but with 2 container columns. When I try with three, the spacing between the image and the name becomes too much. See this:
what was the line of code you were using to initiate the columns? If you notice in mine I use the st.beta_columns functionality to specify the size of the columns by passing a list that changes the size of each column created:
col1, mid, col2 = st.beta_columns([1,1,20])
in my example: col1 and mid columns are the same size col3 holds my content and is 20 times the size of the first 2 columns
if you play around with the ratios of the numbers for the columns you will (very likely) be able to find a ratio that works for you!
no problem, communicating through text isn’t always ideal and I wasn’t as clear as I had hoped!
hmm ok is there white space around your picture? in my example i made sure to choose a picture that had no surrounding whitespace, maybe that is contributing to the big spacing?
Also, are you still using the title_container wrapper? Im double checking this but i am 99% sure that there is no current functionality in Streamlit to put containers in containers, so it might be contributing to your spacing issues.
I was only semi-right on the containers in containers comment.
Currently, you can’t put columns inside another column, or an expander in an expander, but you should be fine to use the beta_container and then use columns or an expander inside!
Thanks again Marisa. I learnt a trick of using a column as a definitive divider between places! The image has as much whitespace because of the shape of the owl. I’ll live with it for now.
Woohoo! Thanks a ton @ash2shukla , this did the trick! I can’t write HTML/CSS/JS to save my life, so your so-called ugly code is better than what I can produce
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.