使我现有的 Excel 文件可供用户在闪亮的应用程序中下载
在我的应用程序中,用户应该从 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您的
www
文件夹与app.r
或server.r/ui.r
文件位于同一目录中。它必须可以被闪亮的服务器读取。由于您没有说明您的应用程序是如何启动/服务的(从您的计算机,在服务器上,什么样的服务器,使用shiny/server,在shinyapps.io,shinyproxy,...),进一步的建议不会很好有用。
我还将文件扩展名添加到
filename = "ph1data.xlsx"
。如果您向 UI 添加
A
标记,它会起作用吗? (target="self" 防止打开新选项卡)如果您将图像(例如
test.jpg
)放入www
文件夹中并添加IMG 标记到您的 UI,它是否显示图像?
Make sure your
www
folder is in the same directory as yourapp.r
orserver.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)If you put and image (eg
test.jpg
) in yourwww
folder and add anIMG
tag to your UI, does it show the image ?