我正在尝试将 Okta OIDC 身份验证和 Dash 集成到 Flask 应用程序中,以便用户只有在使用我们组织的 Okta SSO 登录后才能查看 Dash 应用程序
试:
from flask import Blueprint, Flask, jsonify, redirect, render_template_string, url_for
from flask_oidc import OpenIDConnect
from okta import UsersClient
import dash
oidc = OpenIDConnect()
okta_client = UsersClient("https://dev-XXXXXX.okta.com",
"somesecret")
app = Flask(__name__)
app.config.from_mapping(
SECRET_KEY="testkey",
OIDC_CLIENT_SECRETS="/app/appname/client_secrets.json",
OIDC_COOKIE_SECURE= False,
OIDC_CALLBACK_ROUTE="/oidc/callback",
OIDC_SCOPES=["openid", "email", "profile"],
OIDC_ID_TOKEN_COOKIE_NAME="oidc_token",
DEBUG_TB_INTERCEPT_REDIRECTS = False)
oidc.init_app(app)
dash_app.layout = layout.layout
callbacks.register_dash_callbacks(dash_app)
dash_app.run_server(debug=True)
@app.route("/" , methods=["GET"])
@oidc.require_login
def redirect_to_app():
return redirect(url_for(dash_app.config.requests_pathname_prefix))
Run Code Online (Sandbox Code Playgroud)
给了我以下内容:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position …Run Code Online (Sandbox Code Playgroud) 我试图获取 URL 的当前路径以便对过滤器进行操作,但是当我调用时dcc.Location.pathname无法获取 URL。
知道如何获得它吗?
我尝试过print(Input('url', 'pathname'))但也不起作用。
任何想法?
谢谢
Dash App 中需要有一个回调函数来执行某些操作然后刷新页面,只能使用 HTML A 标签实现页面重新加载。
html.A(html.Button('Refresh Data'),href='/')
Run Code Online (Sandbox Code Playgroud)
必需的:
app.layout = html.Div([html.Button(id="refresh")])
@app.callback(Output('???', '???'),
[Input('refresh', 'n_clicks')])
def refresh(n):
## Perform some action ##
## call python function API ##
## Finally Refresh the Page ##
?
return ?
Run Code Online (Sandbox Code Playgroud) 您好,我在破折号中设计了 3 个按钮,我想在单击按钮时更改按钮的颜色,我知道 @app.callback 中需要更改,但我不确定要更改什么。我想保持一切不变,但颜色应更改为“红色”
谁能帮我这个。
leftButtons = html.Div(id='framework-left-pane',
children=[
dcc.Link( children = html.Button(leftButton1,
id='leftbutton1',
className='roundbutton',
style={'backgroundColor': '#111100', 'color':'white','width':'100%', 'border':'1.5px black solid', 'height': '50px','text-align':'center', 'marginLeft': '20px', 'marginTop': 130}, n_clicks = 0)),
dcc.Link( children = html.Button(leftButton2,
id='leftbutton2',
className='roundbutton',
style={'backgroundColor': '#111100', 'color':'white','width':'100%' , 'border':'1.5px black solid','height': '50px','text-align':'center', 'marginLeft': '20px', 'marginTop': 20},n_clicks = 0)),
dcc.Link( children = html.Button(leftButton3,
id='leftbutton3',
className='roundbutton',
style={'backgroundColor': '#111100', 'color':'white','width':'100%', 'border':'1.5px black solid','height': '50px','text-align':'center', 'marginLeft': '20px', 'marginTop': 20},n_clicks = 0)),
],style={'width':'200px','position':'fixed'})
Run Code Online (Sandbox Code Playgroud)
`
所以现在使用 app.callback 我只返回图像
@app.callback(
Output(component_id='tab_1_images', component_property='children'),
[Input('leftbutton1', 'n_clicks'), …Run Code Online (Sandbox Code Playgroud) 我是该框架的新手Plotly Dash,并尝试构建一个简单的仪表板:
允许用户上传 CSV 文件以进行图形分析。
根据步骤 #1 中上传的文件创建 Pandas 数据框。
2a. 如果尚未选择 CSV 文件(以及生成的数据框),则不渲染任何内容。
根据上述数据框中包含的数据渲染基本条形图(或散点图、热图等)。
我的 CSV 文件中的数据类似于以下内容:
df = pd.DataFrame({'Make':['Ford', 'Ford', 'Ford', 'BMW', 'BMW', 'BMW', Mercedes', 'Mercedes', 'Mercedes'],
'Score':['88.6', '76.6', '100', '79.1', '86.8', '96.4', '97.3', '98.7', '98.5'],
'Dimension':['Speed', 'MPG', 'Styling', 'Speed', 'MPG', 'Styling', 'Speed', 'MPG', 'Styling'],
'Month':['Apr-19', 'Apr-19', 'Apr-19', 'Apr-19', 'Apr-19', 'Apr-19', 'Apr-19', 'Apr-19', 'Apr-19']})
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
import base64
import datetime
import io
import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as …Run Code Online (Sandbox Code Playgroud) 我正在使用该px.bar()函数来Plotly Express创建一些简单的条形图。
我的代码如下:
import plotly.express as px
import pandas as pd
test_df = pd.DataFrame({'Manufacturer':['Ford', 'Ford', 'Mercedes', 'BMW', 'Ford', 'Mercedes', 'BMW', 'Ford', 'Mercedes', 'BMW', 'Ford', 'Mercedes', 'BMW', 'Ford', 'Mercedes', 'BMW', 'Ford', 'Mercedes', 'BMW'],
'Metric':['Orders', 'Orders', 'Orders', 'Orders', 'Orders', 'Orders', 'Orders', 'Sales', 'Sales', 'Sales', 'Sales', 'Sales', 'Sales', 'Warranty', 'Warranty', 'Warranty', 'Warranty', 'Warranty', 'Warranty'],
'Sector':['Germany', 'Germany', 'Germany', 'Germany', 'USA', 'USA', 'USA', 'Germany', 'Germany', 'Germany', 'USA', 'USA', 'USA', 'Germany', 'Germany', 'Germany', 'USA', 'USA', 'USA'],
'Value':[45000, 70000, 90000, 65000, 40000, 65000, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用绘图和破折号构建一个简单的网络仪表板。这是我想要获得的结构:
app = dash.Dash(__name__)
def Build_home_page():
"""
build_welcome_banner [summary]
[extended_summary]
Returns
-------
[type]
[description]
""" ""
return [
html.Div(
id="banner",
className="box",
children=[
html.Div(
id="welcome-user",
children=[
html.H1("WELCOME TO THE DATA SCIENCE"),
html.H1("AND MACHINE LEARNING PLATFORM"),
html.Hr(className="tickline"),
html.Br(),
html.P(id="welcome-text1",
children= [
"That provides you with the tools that allow you to explore your data seemlessly and"
]),
html.P(id= "welcome-text2",
children= [
"get actionable insights from your data and allows you to easily apply Machine learning models to make predictions with your data" …Run Code Online (Sandbox Code Playgroud) 我用 Python 创建了一个简单的 Plotly 图表,并且可以非常轻松地更改模式栏选项。但是,当我尝试将相同的图表发布到 Chart-Studio 时,并非所有模式栏配置都有效。有任何想法吗?
这是代码:
import pandas as pd
import numpy as np
import plotly.graph_objects as go
df = pd.DataFrame({'a':[2,4,6,8,10],'b':[3,6,9,12,15]})
fig = go.Figure()
fig.add_trace(go.Scatter(x=df.index, y=df['a'], mode='lines', name='a', line=dict(color='dodgerblue', dash='solid')))
fig.add_trace(go.Scatter(x=df.index, y=df['b'], mode='lines', name='b', line=dict(color='lightsalmon', dash='dash')))
fig.update_layout(
title='a and b',
autosize=False,
width=500,
height=500,
newshape=dict(line_color='mediumaquamarine', line_width=2, opacity=1)
)
config = {
'modeBarButtonsToAdd' : ['drawline', 'drawopenpath', 'drawrect', 'eraseshape'],
'displaylogo' : False
}
fig.show(config=config)
Run Code Online (Sandbox Code Playgroud)
出现的图形已删除徽标,并且模式栏上的附加按钮按其应有的方式显示...
但是,如果我尝试将其发布到 Chart-Studio:
import chart_studio.plotly as py
import chart_studio
chart_studio.tools.set_credentials_file(username='xxxxx', api_key='#####')
py.plot(fig, filename='a and b', auto_open=False, config=config) …Run Code Online (Sandbox Code Playgroud) 我的仪表板使用 dash,并部署在 AWS Elastic Beanstalk 上。
Datepicker 中存在问题。我正在使用 max_date_allowed=dt.date(dt.now())
因此,在部署应用程序的那天,一切都运行良好。但从第二天开始, max_date_allowed 会固定为应用程序部署的日期,并且我们无法选择超出应用程序部署日期的日期。
仅当我们在环境中从操作菜单中选择重新启动应用程序服务器时,它才会再次起作用。
这里可能有什么问题?
下面是我们使用的日期选择器片段。
dcc.Tabs([
dcc.Tab(label='DDR by Date (Default DDR - Last Day)', value='tab-1', children=[
dcc.DatePickerSingle(
id='my-date-picker-single',
min_date_allowed=dt(2020, 1, 18),
max_date_allowed=dt.date(dt.now()),
initial_visible_month=dt.date(dt.now()),
placeholder='Select a date',
display_format='DD/MM/YYYY'
),
html.Button(id='submit-button', n_clicks=0, children='Submit'),
html.Div(id='output-container-date-picker-single')
]),
Run Code Online (Sandbox Code Playgroud) python datepicker amazon-web-services amazon-elastic-beanstalk plotly-dash