【发布时间】:2020-07-19 19:06:02
【问题描述】:
我正在尝试显示从 DASH 应用程序内的本地路径读取的 pdf。我尝试使用嵌入和 iframe。但是,他们都没有显示pdf。此外,没有错误,它只是空白。下面是代码sn-p。
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import PyPDF2
import docx2txt
from jupyter_dash import JupyterDash
#external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = JupyterDash(__name__)
app.layout = html.Div([
html.Button('Submit',id='submit'),
html.Embed(src="<path to .pdf>",width="750",height="400",type="application/pdf"),
html.Div(id='my-div')
])
@app.callback(
Output(component_id='my-div', component_property='children'),
[Input(component_id='submit', component_property='n_clicks')]
)
def update_output_div(n_clicks):
if n_clicks:
my_text = docx2txt.process("<path to .doc>")
return 'You\'ve entered "{}"'.format(my_text)
app.run_server("inline",port=8060)
我添加了一个提交按钮并读取了一个 word 文件,以确保应用程序本身工作正常。
我正在 Chrome 中的 Jupyter 中运行以下内容。
如果我显示在线 pdf 或网站 url,它可以正常工作。
有什么建议吗?
提前致谢。
【问题讨论】:
标签: python html pdf plotly-dash