使我现有的 Excel 文件可供用户在闪亮的应用程序中下载

发布于 2025-01-15 16:36:26 字数 670 浏览 2 评论 0原文

在我的应用程序中,用户应该从 Excel 文件插入一些数据,但我想让他们能够在计算机中下载一个 (TesteR.xlsx) 并将其用作示例。我尝试申请 this 解决方案,但它不起作用,当我单击按钮时,它会下载一个有点奇怪的文件。

library(shiny)

ui <- fluidPage(
  downloadButton("downloadOP", label = "Download")
)

server <- function(input, output){
  output$downloadOP <- downloadHandler(
    filename = "ph1data",
    content = function(file) {
      file.copy("www/TesteR.xlsx", file)
    }
  )
}

shinyApp(ui, server)

我还将该文件包含在 www 文件夹中,就像其他问题中所建议的那样,但也许我遗漏了一些东西。

任何帮助将非常感激!

In my app, users should insert some data from an Excel file, but I want to make it possible for them to download one (TesteR.xlsx) in their computer and use it as an example. I have tried to apply this solution but it didn't work, when I click the button it downloads a kinda weird file.

library(shiny)

ui <- fluidPage(
  downloadButton("downloadOP", label = "Download")
)

server <- function(input, output){
  output$downloadOP <- downloadHandler(
    filename = "ph1data",
    content = function(file) {
      file.copy("www/TesteR.xlsx", file)
    }
  )
}

shinyApp(ui, server)

I also included the file in a www folder like suggested in the other question, but maybe I am missing something.

Any help would be very much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最笨的告白 2025-01-22 16:36:26

确保您的 www 文件夹与 app.rserver.r/ui.r 文件位于同一目录中。它必须可以被闪亮的服务器读取。

由于您没有说明您的应用程序是如何启动/服务的(从您的计算机,在服务器上,什么样的服务器,使用shiny/server,在shinyapps.io,shinyproxy,...),进一步的建议不会很好有用。

我还将文件扩展名添加到 filename = "ph1data.xlsx"

如果您向 UI 添加 A 标记,它会起作用吗? (target="self" 防止打开新选项卡)

ui <- fluidPage(
  downloadButton("downloadOP", label = "Download"),
  tags$a("Download", href="TesteR.xlsx", target="self")
)

如果您将图像(例如 test.jpg)放入 www 文件夹中并添加 IMG 标记到您的 UI,它是否显示图像?

ui <- fluidPage(
  downloadButton("downloadOP", label = "Download"),
  tags$a("Download", href="TesteR.xlsx", target="self", class="btn btn-primary"),
  tags$img(src="test.jpg")
)

Make sure your www folder is in the same directory as your app.r or server.r/ui.r files. It must be readable by the shiny server.

As you don't state how your app is started/served (from your computer, on a server, what kind of server, using shiny/server, on shinyapps.io, shinyproxy, ...) further advice won't be very useful.

I will also add the file extension to filename = "ph1data.xlsx".

If you add a A tag to your UI, does it work ? (target="self" prevent opening a new tab)

ui <- fluidPage(
  downloadButton("downloadOP", label = "Download"),
  tags$a("Download", href="TesteR.xlsx", target="self")
)

If you put and image (eg test.jpg) in your www folder and add an IMG tag to your UI, does it show the image ?

ui <- fluidPage(
  downloadButton("downloadOP", label = "Download"),
  tags$a("Download", href="TesteR.xlsx", target="self", class="btn btn-primary"),
  tags$img(src="test.jpg")
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文