java - Javafx webview在运行时不显示破折号应用程序
问题描述
我正在尝试将 Dash-plotly 应用程序集成到 Java 应用程序中。
我创建了一个看起来像这样的 Plotly-Dash 应用程序:
代码的 Dash app 组件是这样的:
app = dash.Dash(__name__)
##image_filename = 'tmp.png' # replace with your own image
##encoded_image = base64.b64encode(open(image_filename, 'rb').read())
styles = {
'pre': {
'border': 'thin lightgrey solid',
'overflowX': 'scroll'
}
}
app.layout = html.Div([
html.Div([
html.Div([
dcc.Graph(id='basic-interactions', figure=fig)
], className="seven columns"),
html.Div([
dcc.Markdown("""
**Node Details**
Click node to view details here.
"""),
html.Pre(id='click-data', style={"maxHeight": "500px", "overflow": "scroll"}),
], className="four columns"),
], className="row")
])
@app.callback(
Output('click-data', 'children'),
Input('basic-interactions', 'clickData'))
def display_click_data(clickData):
mydict = ast.literal_eval('{}'.format(clickData))
if mydict!=None:
print_clicked = mydict['points'][0]['text']
for i in full_texts:
if print_clicked == i[0]:
print_clicked = i[1]
if '<br>' in print_clicked:
print_clicked = print_clicked.replace('<br>','\n')
if '<b>' in print_clicked:
print_clicked = print_clicked.replace('<b>','**')
if '</b>' in print_clicked:
print_clicked = print_clicked.replace('</b>','**')
return print_clicked
if __name__ == '__main__':
app.run_server(host='127.0.0.1',port=8050,debug=True)
我还创建了一个 Java 程序,它接受用户输入并使用 javafx WebView 面板在 Java 应用程序中显示 Dash-app。
代码的javafx组件是这样的:
private void setGraph(JPanel pane, String title) throws Exception
{
pane.removeAll();
JFXPanel jfxPanel = new JFXPanel();
pane.setLayout(new BorderLayout());
pane.add(jfxPanel,BorderLayout.CENTER);
Platform.runLater(() -> {
StackPane root = new StackPane();
Scene scene = new Scene(root);
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
boolean result=false;
while(result==false) {
try {
ServerSocket serverSocket = new ServerSocket(8050);
result=true;
} catch (IOException e) {
System.out.println("Could not listen on port: " + 8050);
// ...
}
}
if (result ==true) {
webEngine.load("http://127.0.0.1:8050");
root.getChildren().add(webView);
jfxPanel.setScene(scene);
}
});
pane.updateUI();
}
但是,当我第一次运行 Java 代码时,在http://127.0.0.1:8050创建的 Dash 应用程序不显示。(不过,可以在普通的 chrome 浏览器上看到 Dash 应用程序)
当我第二次运行 Java 代码时,Dash 应用程序出现了,只是因为第一次运行时启动的 dash 应用程序没有终止。
我已验证我的 Java 程序的 Javafx 面板部分在构建 Dash 应用程序的 Python 代码运行之后运行。
我的问题:
我不确定为什么我第一次运行代码时它不显示 Dash 应用程序以及如何解决它......
每次执行程序时如何终止 Dash 应用程序?
我已经坚持了太久了......任何建议将不胜感激。
解决方案
推荐阅读
- github - 如何在 Github 中为 Pytorch 模型提供正确的路径?
- latex - 我找不到我的降价 LaTex 代码有什么问题 (\begin{align} ~ \end{align})
- excel - excel的嵌套AND/OR IF函数
- javascript - JavaScript 日期格式:格式化日期前(星期一)
- python - 将工作日从整数转换为实际名称时出错
- ag-grid - 单元格中的 React(Hooks) 按钮始终返回定义为 useState 的第一个状态值(即使已更改)
- python - Django - 如何在模板中处理来自 TwelveData API 的 JSON 响应?
- java - 添加 JTextField 会产生空的 JFrame
- laravel - 我无法在 laravel 中获取路由 url,下面是我的代码
- javascript - Bootstrap navbar mega menu 在 Asp.Net Core 上不起作用