我有一个超级奇怪的问题,我似乎无法弄清楚--我怀疑这与从临时目录写入/读取有关。所以,我想做的是一个很长的故事,但我已经把问题简化为两个简单的任务。
查看上传的pdf ( UiOutput)
shinyjqui包))
但是,如果我尝试将它们合并到一个闪亮的应用程序中,它总是会导致崩溃。这是我的密码:
library(tidyverse)
library(shiny)
library(shinyjqui)
ui <- fluidPage(
fluidRow(
column(6,
# Input pdf
fileInput("file1", "File"),
# Display an editable table (from shinyjqui)
selectableTableOutput("tbl", selection_mode = "cell")
),
column(6,
# display uploaded pdf
uiOutput("pdfview")
)
)
)
server <- function(input, output, session) {
# ---- pdf (1)
addResourcePath("pdf", tempdir())
test_file <- reactive({
req(input$file1$datapath)
readBin(con=input$file1$datapath,what = 'raw',n=input$file1$size)
})
observe({
temp <- paste0(resourcePaths(), "/doc.pdf")
writeBin(test_file(), temp)
output$pdfview <- renderUI({
tags$iframe(style="height:600px; width:100%", src="pdf/doc.pdf")
})
})
# ---- pdf (1)
# --- selectableTable (2)
get_dummy_data <- reactive({
# random dataframe
data.frame(col1 = c(1,2,3),col2 = c(1,2,3),col3 = c(1,2,3))
})
output$tbl <- renderTable(get_dummy_data(), rownames = TRUE)
# --- selectableTable (2)
}
shinyApp(ui, server)请注意,如果您运行上述可选择的工作,然而,当你上传一个pdf,它崩溃。此外,如果您注释掉块2(可选),pdf查看器工作(专门用于浏览器-而不是闪亮的弹出式窗口)。内存中发生了一些奇怪的事情,因为如果你运行没有块2的应用程序,pdf查看器就能工作,然后如果你将块2放入图片中,它就会崩溃--但是如果你再次删除块2并重新运行它,它根本就不能工作(它处于与最初工作状态相同的状态),我必须关闭并重新打开这个项目,以便pdf查看器工作。以下是错误:
Warning: Error in file: invalid 'description' argument
46: file
45: writeBin
44: <observer> [C:/Users/Chroo/OneDrive//Clients//Sandbox_0080921/test_pdf_viewer.R#34]
1: runApp知道发生什么事了吗?
发布于 2021-09-09 21:38:52
好的,经过一些浏览,我在https://www.py4u.net/discuss/1545522上找到了@amrrs的解决方案。这个问题与二进制读写有关,因此产生了奇怪的记忆行为。可以通过复制输入文件来避免这个问题,因为这样就避免了与shinyjqui的冲突。
server <- shinyServer(function(input, output) {
observe({
req(input$file1)
#Remove
#test_file <- readBin(input$file1$datapath, what="raw")
#writeBin(test_file, "myreport.pdf")
#cat(input$file1$datapath)
# Replace
file.copy(input$file1$datapath,"www", overwrite = T)
output$pdfview <- renderUI({
tags$iframe(style="height:600px; width:100%", src="0.pdf")
})
})
})https://stackoverflow.com/questions/69110300
复制相似问题