So I have this quiz to calculate how attractive someone is, and I want to make a web app so people can use it, problem is, either the code executes in PyCharm only or it doesn’t print nowhere at all. I want it to print this directly into the streamlit webapp so it works exactly the same it works in pycharm. Thanks in advance!
# Introduction
import streamlit
def start():
from time import sleep
print("SMV Calculator Version 1.0")
sleep(1)
print("Hello, today we will calculate precisely how attractive you are out of 10")
sleep(3)
print(""
"")
print("The results you receive will likely be shocking, don't get offended.")
sleep(3)
print(""
"")
print(
"You will receive a short term value (...) and a long term value (...)")
sleep(3)
print(""
"")
print("We will ask you questions about your characteristics in intergender and relationship scenarios")
sleep(3)
print(""
"")
print("PLEASE BE COMPLETELY HONEST, UNHONEST ANSWERS MEANS UNHONEST RESULTS!")
sleep(3)
selection = str(input("Please type in your gender (0 for male and 1 for female) to start! "))
if selection == "0":
maleagepoints = 0
from smvapp import malevariables
elif selection == "1":
femaleagepoints = 0
from smvapp import femalevariables
elif selection != "0" or "1":
print("You literally had one job, to enter one or zero... Refresh and listen to directions.")
print(streamlit.title(start()))
In order to print your lines within the web application, you need to use st.write syntax. Similarly, in case of intereactive input, you can also use, st.text_input widget . Please refer to the doc for a quick start. Below a relavant snippet.
import streamlit as st
# Get user input
value = st.number_input(label = "Please enter 0 or 1 to start!",min_value = 0, max_value = 1, value = 1)
if value == 0 :
st.write("User is Unhapppy :worried:") # Print within the app
else:
st.write("User is Happy :grinning:")
Exactly! Please use Streamlit syntax. For example - instead of input, use streamlit widget (number_input, text_input etc) or instead of print, use write or markdown - streamlit syntax. Do refer to the doc as well for more information .In that way, your codes will start to interact within the web app, and you can build one !
Cheers
Avra
Hi, I am checking a basic question here, will all python functions and commands work along side streamlit funtions or commands ? print, type does not give any out put like it does in juypternotebook. or pycharm
For example when we write st.write(x) it shows the x variable value but when we write print(x) system does not give any error nor gives an output same goes with type(x). It seems the output of print/type is getting supressed when used along side streamlit. Your thoughts please.
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.