我目前正在制作一个 Dash 应用程序,它会根据用户权限显示不同的布局,所以我希望能够识别注册的用户。我正在使用基本身份验证,我更改了 dash_auth/basic_auth.py 中的一些行:原始:
username_password_utf8 = username_password.decode('utf-8')
username, password = username_password_utf8.split(':')
Run Code Online (Sandbox Code Playgroud)
到:
username_password_utf8 = username_password.decode('utf-8')
username, password = username_password_utf8.split(':')
self._username = username
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我尝试使用来自 auth 的 _username 属性时,我收到了:AttributeError: 'BasicAuth' object has no attribute '_username' 错误。
app.layout = html.Div(
html.H3("Hello " + auth._username)
)
Run Code Online (Sandbox Code Playgroud)
我知道在授权检查之前已经处理了 Dash 应用程序,但我不知道在哪里实现根据用户名更改布局的回调。如何在 Dash 应用程序中获取用户名?
我在为线图自定义颜色方面遇到了一些麻烦.我想展示一系列具有连续调色板的光谱.参数"palette ="blues"工作正常,但不接受任何合适的颜色列表(如"Blues_d"),它们不包含任何明亮的颜色.

下面你可以看到我正在使用的代码.
color = (sns.dark_palette("purple"))
sns.set()
ax = sns.lineplot(x="Wavelength", y="Absorption", hue="t (min)", lw=1, data=df1, palette=color, legend="brief")
Run Code Online (Sandbox Code Playgroud)
问题是,我收到以下错误:
ValueError:调色板列表的颜色数量错误.
所以问题是:我如何使用线条图功能并使用蓝色,红色或其他任何不包含任何亮色的顺序调色板?
我使用的是pandas版本0.23.3,matplotlib版本2.2.2和seaborn版本0.9.0
我正在尝试更改我正在构建的直方图的图形大小.我收到错误:
distplot() got an unexpected keyword argument 'figsize'
Run Code Online (Sandbox Code Playgroud)
我试图运行的代码是这样的:
sns.distplot(MSoft['pct_change'].dropna(), bins=100, color='magenta', figsize=(20,8))
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Dash Plot 将输入值传递给另一个。
主页上有一个策略列表:
First_page = html.Div([
html.Div([dcc.Dropdown(id='strategy', options=[{'label': i, 'value': i} for i in [strat1, start2]], multi=True)], value = [strat1]),
html.Div([dcc.Input(id='date_start', type='text', value='1990-01-01')]),
html.Button('Start Calculation', id='button'),
])
Run Code Online (Sandbox Code Playgroud)
我的第 1 页和第 2 页如下:
for i in range(2) :
layout = html.Div([
html.Div([dcc.Dropdown(id='strategy'+str(i), options=[{'label': i, 'value': i} for i in [strat1, start2]]])], value = strat+str(i)),
html.Div([dcc.Input(id='date_start'+str(i), type='text', value='1990-01-01')]),
html.Button('Start Calculation', id='button'+str(i)),
+ other options not listed in main page
])
Run Code Online (Sandbox Code Playgroud)
目标如下:当用户在主页上时,他可以选择他想要查看的策略列表以及开始日期。
然后当他按下按钮时,它应该为每个选择的策略打开页面(在这个例子中我们有 2 个策略,所以我应该有 2 个页面:localhost:port/page-strat1 和 localhost:port/page-strat2),如图所示在每一页上都以所选日期开始。
我成功打开页面 localhost:port/strat1 …
我对 Python 中的排名很好奇。输出如何到达,如下所示?排名对数据有什么影响?
Input obj = pd.Series([7,-5,7,4,2,0,4])
Run Code Online (Sandbox Code Playgroud)
输出:
print(obj)
0 7
1 -5
2 7
3 4
4 2
5 0
6 4
Run Code Online (Sandbox Code Playgroud)
秩
print(obj.rank())
0 6.5
1 1.0
2 6.5
3 4.5
4 3.0
5 2.0
6 4.5
Run Code Online (Sandbox Code Playgroud) 使用Dash 0.22.0和Python 2.7.12。Plotly 是 3.1.0,但未在以下示例中使用。
我正在尝试创建一个应该完全脱机工作的最小应用程序。
而不是从远程加载的dash_html_components/bundle.js,dash_renderer/bundle.js,react.min.js和react-dom.min.js,我把自己的本地副本在/assets/js。我想告诉 Dash 只使用这些文件的本地副本。
我阅读了资产文件和索引自定义#286,如果我理解得很好,下面的例子应该可以工作:
# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
# default values
app.config.assets_folder = 'assets' # The path to the assets folder.
app.config.include_asset_files = True # Include the files in the asset folder
app.config.assets_external_path = "" # The external prefix if serve_locally == False
app.config.assets_url_path …Run Code Online (Sandbox Code Playgroud) 我构建了一个Flask应用程序,我想使用Plotly为我的数据嵌入一个图表。我对Plotly进行了一些研究,发现它与Dash有关,并且在确定我的项目需要使用这两个方法中的哪一个时遇到了一些麻烦。它们之间有什么区别?
所以我有
hours = [x for x in range(7,18)]
columns = [1, 2, 3, 4, 5]
matrixDatos = [[0,1,0,1,0],
[0,1,0,1,1],
[2,3,2,3,2],
[2,3,2,3,3],
[4,5,4,5,4],
[4,5,4,5,5],
[6,7,6,7,6],
[6,7,6,7,7],
[8,9,8,9,8],
[8,9,8,9,8]
]
table = ff.create_table(matrixDatos)
fig = ff.create_annotated_heatmap(matrixDatos, x=columns, y=hours, colorscale='Viridis')
Run Code Online (Sandbox Code Playgroud)
但是它打印y轴从18到7的热图,是否有办法从7到18打印它?
免责声明:我是aiohttp的初学者
我正在尝试使用aiohttp异步处理get请求但事实证明它比gevent的池版本慢得多.
GEVENT VERSION
import gevent
from gevent import monkey
monkey.patch_all()
from gevent.pool import Pool
import requests
import time
def pooling_task(url):
requests.get(url)
def pooling_main():
start = time.time()
pool = Pool(10)
urls = [
"http://google.com",
"http://yahoo.com",
"http://linkedin.com",
"http://shutterfly.com",
"http://mypublisher.com",
"http://facebook.com"
]
for url in urls:
pool.apply_async(pooling_task, args=(url,))
pool.join()
end = time.time()
print("POOL TIME {}".format(end-start))
if __name__ == '__main__':
print("POOLING VERSION")
pooling_main()
Run Code Online (Sandbox Code Playgroud)
输出 - 池时间6.299163818359375
以下是aiohttp版本
import aiohttp
import asyncio
import time
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
async def fetch(session, url):
async with session.get(url) …Run Code Online (Sandbox Code Playgroud)