将铯应用程序添加到Plotly Dash不起作用

2024-09-27 02:14:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将铯集成到我的Plotly Dash应用程序中,但当我从Jupyter笔记本本地运行该应用程序时,它不会在Plotly Dash中呈现铯应用程序。我的python代码如下所示:

import dash
import dash_html_components as html
external_css = ['https://cesium.com/downloads/cesiumjs/releases/1.76/Build/Cesium/Widgets/widgets.css']

app = dash.Dash(__name__, 
                title='Cesium Test',
                external_stylesheets=external_css)

app.layout = html.Div(id='blah',
                      children=[
                          'Testing...',
                          html.Script(src='https://cesium.com/downloads/cesiumjs/releases/1.76/Build/Cesium/Cesium.js'),
                          html.Div(id='cesiumContainer'),
                          html.Script('''
          Cesium.Ion.defaultAccessToken = 'any_code_works';
          var viewer = new Cesium.Viewer('cesiumContainer');
                          ''')
                      ])

if __name__ == '__main__':
    app.run_server(debug=True, use_reloader=False)

下面是一个工作示例(单击“显示”按钮查看它渲染铯应用程序):

https://glitch.com/edit/#!/hyper-sixth-hope?path=index.html%3A17%3A11


Tags: httpsimportcomapp应用程序downloadshtmlplotly
1条回答
网友
1楼 · 发布于 2024-09-27 02:14:43

@alexcjohnson帮我完成了Plotly community

以下是工作代码:

import dash
import dash_html_components as html
from dash.dependencies import Input, Output

external_css = ['https://cesium.com/downloads/cesiumjs/releases/1.76/Build/Cesium/Widgets/widgets.css']
external_scripts = [{'src':'https://cesium.com/downloads/cesiumjs/releases/1.76/Build/Cesium/Cesium.js'}]

app = dash.Dash(__name__, 
                title='Cesium Test',
                external_scripts=external_scripts,
                external_stylesheets=external_css)

app.layout = html.Div(id='blah',
                      children=[
                          'Testing...',
                          html.Div(id='cesiumContainer')
                      ])

app.clientside_callback(
    '''
    function(id) {
        Cesium.Ion.defaultAccessToken = "any_code_works";
        var viewer = new Cesium.Viewer(id);
        return true;
    }
    ''',
    Output('cesiumContainer', 'data-done'),
    Input('cesiumContainer', 'id')
)

if __name__ == '__main__':
    app.run_server(debug=True, use_reloader=False)

相关问题 更多 >

    热门问题