测试

测试#

from dash_xinet.server import run_server, create_app

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = create_app(__name__, external_stylesheets=external_stylesheets)
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 from dash_xinet.server import run_server, create_app
      3 external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
      4 app = create_app(__name__, external_stylesheets=external_stylesheets)

File /usr/share/miniconda/lib/python3.11/site-packages/dash_xinet/server.py:1
----> 1 from jupyter_dash import JupyterDash as Dash
      2 import socket
      4 # def interpolate_str(template, **data):
      5 #     s = template
      6 #     for k, v in data.items():
      7 #         key = "{%" + k + "%}"
      8 #         s = s.replace(key, v)
      9 #     return s

ModuleNotFoundError: No module named 'jupyter_dash'
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
/tmp/ipykernel_2004/3587667030.py:1: UserWarning: 
The dash_core_components package is deprecated. Please replace
`import dash_core_components as dcc` with `from dash import dcc`
  import dash_core_components as dcc
/tmp/ipykernel_2004/3587667030.py:2: UserWarning: 
The dash_html_components package is deprecated. Please replace
`import dash_html_components as html` with `from dash import html`
  import dash_html_components as html
layout = html.Div([
    dcc.Location(id='url', refresh=False),
    html.Div(id='page-content')
])


index_page = html.Div([
    dcc.Link('Go to Page 1', href='/page-1'),
    html.Br(),
    dcc.Link('Go to Page 2', href='/page-2'),
])

page_1_layout = html.Div([
    html.H1('Page 1'),
    dcc.Dropdown(
        id='page-1-dropdown',
        options=[{'label': i, 'value': i} for i in ['LA', 'NYC', 'MTL']],
        value='LA'
    ),
    html.Div(id='page-1-content'),
    html.Br(),
    dcc.Link('Go to Page 2', href='/page-2'),
    html.Br(),
    dcc.Link('Go back to home', href='/'),
])


@app.callback(Output('page-1-content', 'children'),
              [Input('page-1-dropdown', 'value')])
def page_1_dropdown(value):
    return f'You have selected "{value}"'


page_2_layout = html.Div([
    html.H1('Page 2'),
    dcc.RadioItems(
        id='page-2-radios',
        options=[{'label': i, 'value': i} for i in ['Orange', 'Blue', 'Red']],
        value='Orange'
    ),
    html.Div(id='page-2-content'),
    html.Br(),
    dcc.Link('Go to Page 1', href='/page-1'),
    html.Br(),
    dcc.Link('Go back to home', href='/')
])


@app.callback(Output('page-2-content', 'children'),
              [Input('page-2-radios', 'value')])
def page_2_radios(value):
    return f'You have selected "{value}"'


# 更新 index
@app.callback(Output('page-content', 'children'),
              [Input('url', 'pathname')])
def display_page(pathname):
    if pathname == '/page-1':
        return page_1_layout
    elif pathname == '/page-2':
        return page_2_layout
    else:
        return index_page
    # 你也可以在这里返回一个404 "URL not found"
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[3], line 28
      7 index_page = html.Div([
      8     dcc.Link('Go to Page 1', href='/page-1'),
      9     html.Br(),
     10     dcc.Link('Go to Page 2', href='/page-2'),
     11 ])
     13 page_1_layout = html.Div([
     14     html.H1('Page 1'),
     15     dcc.Dropdown(
   (...)
     24     dcc.Link('Go back to home', href='/'),
     25 ])
---> 28 @app.callback(Output('page-1-content', 'children'),
     29               [Input('page-1-dropdown', 'value')])
     30 def page_1_dropdown(value):
     31     return f'You have selected "{value}"'
     34 page_2_layout = html.Div([
     35     html.H1('Page 2'),
     36     dcc.RadioItems(
   (...)
     45     dcc.Link('Go back to home', href='/')
     46 ])

NameError: name 'app' is not defined
port = 5555
app.config.suppress_callback_exceptions = True
await run_server(app, layout, port=port)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[4], line 2
      1 port = 5555
----> 2 app.config.suppress_callback_exceptions = True
      3 await run_server(app, layout, port=port)

NameError: name 'app' is not defined