首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查看器(UiOutput)和selectableTableOutput (shinyjqui包)中的临时内存错误

查看器(UiOutput)和selectableTableOutput (shinyjqui包)中的临时内存错误
EN

Stack Overflow用户
提问于 2021-09-08 22:25:57
回答 1查看 43关注 0票数 0

我有一个超级奇怪的问题,我似乎无法弄清楚--我怀疑这与从临时目录写入/读取有关。所以,我想做的是一个很长的故事,但我已经把问题简化为两个简单的任务。

查看上传的pdf ( UiOutput)

  • Use可选择(来自shinyjqui包)

)

但是,如果我尝试将它们合并到一个闪亮的应用程序中,它总是会导致崩溃。这是我的密码:

代码语言:javascript
复制
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查看器工作。以下是错误:

代码语言:javascript
复制
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

知道发生什么事了吗?

EN

回答 1

Stack Overflow用户

发布于 2021-09-09 21:38:52

好的,经过一些浏览,我在https://www.py4u.net/discuss/1545522上找到了@amrrs的解决方案。这个问题与二进制读写有关,因此产生了奇怪的记忆行为。可以通过复制输入文件来避免这个问题,因为这样就避免了与shinyjqui的冲突。

代码语言:javascript
复制
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")
  })

  })

})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69110300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档