如何在Python Shiny中显示本地PDF文件

问题描述 投票:0回答:1

我正在编写一个 Shiny 应用程序,并尝试在应用程序中显示本地 PDF 文件。无论我尝试哪条路径,我都会收到“未找到”错误。

这是我的代码(仍然给出“未找到”错误):

from shiny import App, Inputs, Outputs, Session, render, ui
import shiny.experimental as x


items = [x.ui.accordion_panel("Instructions", "Instructions for use"),
         x.ui.accordion_panel("Docs", ui.output_ui("pdf"))]

app_ui = ui.page_fluid(
    ui.h2("Test"),
    x.ui.accordion(*items, id="acc")
)

def server(input: Inputs, output: Outputs, session: Session):
    @output
    @render.ui
    def pdf():
        return ui.tags.iframe(src="Test.pdf", width="50%", height="200%")
        

app = App(app_ui, server) 

文件“Test.pdf”(我要显示的pdf文件)与应用程序位于同一文件夹中,我还尝试创建一个名为“www”的文件夹并在其中存储“Test.pdf”。如果我用 PDF 显示的 URL 替换本地路径,但我似乎无法弄清楚为什么无法显示本地 PDF 文件。

python pdf py-shiny
1个回答
0
投票

我在本地启动应用程序时遇到同样的问题。

© www.soinside.com 2019 - 2024. All rights reserved.