如何仅在破折号应用程序上显示白色参考?
How does only shows a white referencial on dash application?
我正在尝试在 dash 中部署一些应用程序,但是,虽然下拉菜单看起来正确,但没有调用绘图。
我已经尝试了很多不同的东西,但它总是指向白色参考...
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import numpy as np
import pandas as pd
import plotly.graph_objs as go
import plotly.express as px
import plotly.io as pio
from plotly.colors import n_colors
from plotly.subplots import make_subplots
df = pd.read_csv('movies.csv', encoding = "ISO-8859-1")
df.columns = df.columns.str.capitalize()
###################### APP ############################
app = dash.Dash(__name__)
app.layout = html.Div([
html.Div([
dcc.Graph(id = 'our_graph')
],className = 'nine columns'),
html.Div([
html.Br(),
html.Label(['Choose Country / Genre / Company:'],style={'font-weight': 'bold', "text-align": "center"}),
dcc.Dropdown(id = 'country_drop',
options = [{'label':country, 'value':country} for country in df['Country'].unique()],
value = 'USA',
multi = False,
disabled=False,
clearable=True,
searchable=True,
placeholder='Choose Country...',
className='form-dropdown',
style={'width':"90%"},
persistence='string',
persistence_type='memory'),
dcc.Dropdown(id= 'genre_drop',
options = [{'label': genre, 'value' : genre} for genre in df['Genre'].unique()],
value = 'Drama',
multi = False,
disabled=False,
clearable=True,
searchable=True,
placeholder='Choose Genre..',
className='form-dropdown',
style={'width':"90%"},
persistence='string',
persistence_type='memory'),
dcc.Dropdown(id = 'company_drop',
options = [{'label':company, 'value':company} for company in df['Company'].unique()],
value = 'Paramount Pictures',
multi = False,
disabled=False,
clearable=True,
searchable=True,
placeholder='Choose Company..',
className='form-dropdown',
style={'width':"90%"},
persistence='string',
persistence_type='memory'),
],className='three columns')
])
####################Callbacks#######################
@app.callback(
dash.dependencies.Output('our_graph', 'figure'),
[dash.dependencies.Input("company_drop", "value"),
dash.dependencies.Input("country_drop", "value"),
dash.dependencies.Input("genre_drop", "value")
]
)
def plots(country, genre,company):
new_df = df.loc[(df['Country'] == country) & (df['Genre'] == genre) & (df['Company'] == company)]
revenue_df = new_df.groupby(by = ['Year'])['Gross','Budget'].sum()
fig = px.line(revenue_df, x=revenue_df.index, y=revenue_df.columns, title = 'Which Country has the highest revenue by category?',
labels=dict(x="Year", y= 'Amount of $ in billions'))
return fig
#Run App
if __name__ == '__main__':
app.run_server(debug=False)`
如果有人可以帮助我...我是初学者,但虽然它可能很简单,但我已经在 2 天内寻找解决方案...
数据不显示的原因是下拉的顺序和graph函数接收的顺序不一样,所以获取到的数据不存在,导致报错。
@app.callback(
dash.dependencies.Output('our_graph', 'figure'),
dash.dependencies.Input("company_drop", "value"),
dash.dependencies.Input("country_drop", "value"),
dash.dependencies.Input("genre_drop", "value"))
def plots(company, country, genre):
new_df = df[(df['Country'] == country) & (df['Genre'] == genre) & (df['Company'] == company)]
revenue_df = new_df.groupby(by = ['Year'])[['Gross','Budget']].sum()
revenue_df.reset_index(inplace=True)
fig = px.line(revenue_df,
x='Year',
y=['Gross', 'Budget'],
title='Which Country has the highest revenue by category?',
)
fig.update_xaxes(title_text='YEAR')
fig.update_yaxes(title_text='Amount of $ in billions')
return fig
我正在尝试在 dash 中部署一些应用程序,但是,虽然下拉菜单看起来正确,但没有调用绘图。
我已经尝试了很多不同的东西,但它总是指向白色参考...
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import numpy as np
import pandas as pd
import plotly.graph_objs as go
import plotly.express as px
import plotly.io as pio
from plotly.colors import n_colors
from plotly.subplots import make_subplots
df = pd.read_csv('movies.csv', encoding = "ISO-8859-1")
df.columns = df.columns.str.capitalize()
###################### APP ############################
app = dash.Dash(__name__)
app.layout = html.Div([
html.Div([
dcc.Graph(id = 'our_graph')
],className = 'nine columns'),
html.Div([
html.Br(),
html.Label(['Choose Country / Genre / Company:'],style={'font-weight': 'bold', "text-align": "center"}),
dcc.Dropdown(id = 'country_drop',
options = [{'label':country, 'value':country} for country in df['Country'].unique()],
value = 'USA',
multi = False,
disabled=False,
clearable=True,
searchable=True,
placeholder='Choose Country...',
className='form-dropdown',
style={'width':"90%"},
persistence='string',
persistence_type='memory'),
dcc.Dropdown(id= 'genre_drop',
options = [{'label': genre, 'value' : genre} for genre in df['Genre'].unique()],
value = 'Drama',
multi = False,
disabled=False,
clearable=True,
searchable=True,
placeholder='Choose Genre..',
className='form-dropdown',
style={'width':"90%"},
persistence='string',
persistence_type='memory'),
dcc.Dropdown(id = 'company_drop',
options = [{'label':company, 'value':company} for company in df['Company'].unique()],
value = 'Paramount Pictures',
multi = False,
disabled=False,
clearable=True,
searchable=True,
placeholder='Choose Company..',
className='form-dropdown',
style={'width':"90%"},
persistence='string',
persistence_type='memory'),
],className='three columns')
])
####################Callbacks#######################
@app.callback(
dash.dependencies.Output('our_graph', 'figure'),
[dash.dependencies.Input("company_drop", "value"),
dash.dependencies.Input("country_drop", "value"),
dash.dependencies.Input("genre_drop", "value")
]
)
def plots(country, genre,company):
new_df = df.loc[(df['Country'] == country) & (df['Genre'] == genre) & (df['Company'] == company)]
revenue_df = new_df.groupby(by = ['Year'])['Gross','Budget'].sum()
fig = px.line(revenue_df, x=revenue_df.index, y=revenue_df.columns, title = 'Which Country has the highest revenue by category?',
labels=dict(x="Year", y= 'Amount of $ in billions'))
return fig
#Run App
if __name__ == '__main__':
app.run_server(debug=False)`
如果有人可以帮助我...我是初学者,但虽然它可能很简单,但我已经在 2 天内寻找解决方案...
数据不显示的原因是下拉的顺序和graph函数接收的顺序不一样,所以获取到的数据不存在,导致报错。
@app.callback(
dash.dependencies.Output('our_graph', 'figure'),
dash.dependencies.Input("company_drop", "value"),
dash.dependencies.Input("country_drop", "value"),
dash.dependencies.Input("genre_drop", "value"))
def plots(company, country, genre):
new_df = df[(df['Country'] == country) & (df['Genre'] == genre) & (df['Company'] == company)]
revenue_df = new_df.groupby(by = ['Year'])[['Gross','Budget']].sum()
revenue_df.reset_index(inplace=True)
fig = px.line(revenue_df,
x='Year',
y=['Gross', 'Budget'],
title='Which Country has the highest revenue by category?',
)
fig.update_xaxes(title_text='YEAR')
fig.update_yaxes(title_text='Amount of $ in billions')
return fig