Streamlit markdown in function or in script

Hello
I found a strange behavior with streamlit. Maybe it’s not a bug, but a feature, but I have some difficulties to understand why…

Here is a small example (I found this on a large example)

import streamlit as st

# footer
footer = """<style> .footer {
position: fixed; left: 0; bottom: 0; width: 100%; background-color: white; color: black; text-align: center;
}
</style>
<div class="footer">
This is a test
</div>
"""
st.markdown(footer, unsafe_allow_html=True)

It put a footer on the bottom of the page (using html)

If I change it and put it on a function:

import streamlit as st

def main():
	# footer
	footer = """<style> .footer {
	position: fixed; left: 0; bottom: 0; width: 100%; background-color: white; color: black; text-align: center;
	}
	</style>
	<div class="footer">
	This is a test
	</div>
	"""
	st.markdown(footer, unsafe_allow_html=True)

main()

Then, the behavior is not the same, and the html is not processed…

Any idea why the behavior is not the same ???
(This is a very simple example. In my real life code, I did not write things like that, but some parts of the streamlit code are put in function, and it produces the same strange behavior)

Thank you !
Thibault

Hi @Thib, welcome to the Streamlit community!

You’re right, this is a weird behavior. I wonder if the Streamlit ‘magic’ sees the first one as a st.markdown call and the second one as a generic function call, so it treats them as different rendering types.

If so, I’m not sure what to suggest in the near-term other than not doing that.

Best,
Randy

Hi @randyzwitch, thanks for your answer.
I’ve changed my program to not use a function, but it has implied a lot of changes in my code…

Should I open somewhere an issue (even it is not urgent) so that Streamlit keep track of it and maybe solve this (small) issue ?

Yes, leaving an issue is probably a good next step. I did a brief scan, don’t think anyone else has reported this.

Best,
Randy

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.