我想为我的简单line_chartin中的 x 和 y 轴添加标签streamlit。
绘图命令是
st.line_chart(df[["capacity 1", "capacity 2"]])
Run Code Online (Sandbox Code Playgroud)
line_chart它用 2 条线(容量 1 和容量 2)绘制 a 。
是否有一个简单的命令来添加 x 和 y 轴标签(也许还有图表标题)?
我使用以下代码设置了数据框的样式:
th_props = [
('font-size', '14px'),
('text-align', 'center'),
('font-weight', 'bold'),
('color', '#6d6d6d'),
('background-color', '#f7ffff')
]
td_props = [
('font-size', '12px')
]
styles = [
dict(selector="th", props=th_props),
dict(selector="td", props=td_props)
]
df2=outputdframe.style.set_properties(**{'text-align': 'left'}).set_table_styles(styles)
Run Code Online (Sandbox Code Playgroud)
但它不适用于streamlit。那么,知道如何在 Streamlit 上设置数据框的样式吗?

谁能帮我?
这里没有代码,只是一个问题。我尝试了各种方法来让 Streamlit 应用程序在 Flask 应用程序中运行。主要原因?使用 Flask 对 Streamlit 应用程序进行用户身份验证。无法让它发挥作用。或许这不可能吗?
我想在Streamlit text_area小部件中捕获文本(例如,但任何生成输入的小部件都应该以相同的方式工作),并将捕获的文本传递给回调。我怎么能这么做呢?(如果它是可能的)。
到目前为止我已经尝试过:
import streamlit as st
def callback(string):
print(string) # do something using a string here
Run Code Online (Sandbox Code Playgroud)
然后要么
text_input = st.text_area("Enter a text", key="input_text",
on_change=callback,
args=(text_input,))
# text_input does not exist
Run Code Online (Sandbox Code Playgroud)
或者
text_input = st.text_area("Enter a text", key="input_text",
on_change=callback,
args=(st.session_state.input_text,))
# session_state.input_text is not initialized
Run Code Online (Sandbox Code Playgroud)
两者都会导致错误。
我的基本用法是例如:
我找到了解决方法
input_text= st.text_area("Enter a text", key="input_text")
if input_text!= st.session_state.input_text:
callback(input_text)
st.session_state.input_text = input_text
st.button("Callback", on_click=callback(input_text))
Run Code Online (Sandbox Code Playgroud)
遵循关于数据科学的教程,但我对它并不完全满意,因为它有两个可能相互竞争的小部件,而我只需要一个。
如何使用 Streamlit 将按钮居中,以便该按钮仍可点击?这是一个返回随机数的按钮的小例子:
import streamlit as st
import numpy as np
if st.button('Click'):
rand = np.random.standard_normal()
st.write(str(rand))
Run Code Online (Sandbox Code Playgroud)
我已经看到了标题降价的解决方案,但没有看到诸如按钮之类的交互式元素的解决方案。
我正在构建一个streamlit带有图表的应用程序plotly。但是,我发现很难在图中设置动态绘图宽度plotly(我希望以多种分辨率查看该应用程序)。
有没有办法告诉plotly使用宽度的 100%(或 80% 等)(无论像素数量是多少)。
我正在尝试显示 Streamlit/Hydralit 组件,但是当我将其部署到 Cloud Run 上时,我遇到了此超时错误(本地从未遇到过):
Your app is having trouble loading the hydralit_components.NavBar.nav_bar component.
(The app is attempting to load the component from **, and hasn't received its "streamlit:componentReady"** message.)
If this is a development build, have you started the dev server?
If this is a release build, have you compiled the frontend?
For more troubleshooting help, please see the Streamlit Component docs or visit our forums.
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个相关问题?
我正在使用新的多页功能,并且想要设计我的多页应用程序的样式,并将带有标题的徽标放在页面导航的顶部/之前。
这是在以下目录结构中Python 3.9测试的一个小示例:streamlit==1.11.1
/Home.py
/pages/Page_1.py
/pages/Page_2.py
Run Code Online (Sandbox Code Playgroud)
Home.py:
import streamlit as st
st.sidebar.markdown(
"My Logo (sidebar) should be on top of the Navigation within the sidebar"
)
st.markdown("# Home")
Run Code Online (Sandbox Code Playgroud)
Page_1.py:
import streamlit as st
st.markdown("Page 1")
Run Code Online (Sandbox Code Playgroud)
Page_2.py:
import streamlit as st
st.markdown("Page 2")
Run Code Online (Sandbox Code Playgroud)
我可以使用以下命令运行:
$ streamlit run Home.py
Run Code Online (Sandbox Code Playgroud)
有什么办法可以做到这一点吗?欢迎任何提示!
最美好的祝愿,科德
有没有办法streamlit run APP_NAME.py从 python 脚本中运行命令,它可能看起来像:
import streamlit
streamlit.run("APP_NAME.py")
Run Code Online (Sandbox Code Playgroud)
由于我正在处理的项目需要跨平台(并打包),因此我不能安全地依赖对os.system(...)或的调用subprocess。
目标是在后台提取实时数据(例如每 5 秒)并在需要时提取到仪表板。这是我的代码。它有点工作,但我看到两个问题: 1.如果我将 st.write("TESTING!") 移到最后,由于 while 循环,它永远不会被执行。有办法改进吗?我可以想象,随着仪表板的增长,将会有多个页面/表格等。这不会提供太多的灵活性。2. async 函数中的 return px 行,我对此不太满意,因为我通过反复试验得到了正确的结果。抱歉,我是个新手,但如果有更好的方法,我将非常感激。
谢谢你!
import asyncio
import streamlit as st
import numpy as np
st.set_page_config(layout="wide")
async def data_generator(test):
while True:
with test:
px = np.random.randn(5, 1)
await asyncio.sleep(1)
return px
test = st.empty()
st.write("TESTING!")
with test:
while True:
px = asyncio.run(data_generator(test))
st.write(px[0])
Run Code Online (Sandbox Code Playgroud)