下载已编辑的数据表在闪亮的应用程序中发出警告 [英] download edited data table gives warning in shiny app

查看:49
本文介绍了下载已编辑的数据表在闪亮的应用程序中发出警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个示例闪亮的应用程序,允许用户下载可编辑的表格.用户可以单击左上角的 csv 按钮下载表格.

Here is an example shiny app that allows user to download editable table. User can click on the csv button on the upper left corner to download the table.

但是,我在编辑表中的任何单元格后(通过双击任何单元格并修改内容)发现,当我单击 csv 按钮时,输入文件名并保存后,我得到了警告消息如下:

However, I found after I edit any cell in the table (by double click on any cell and modify contents), when I click on the csv button, enter file name and save, I got warning message like below:

dataTables warning: table id=DataTables_Table_3 - invalid json response. 
For more information about this error, please see http://datatables.net/tn/1

尽管我仍然可以将表另存为csv文件,但警告消息却非常令人讨厌.

Although I was still able to save the table as csv file, the warning message is very annoying.

这仅在我在 renderDT 函数中添加参数 server = FALSE 后才会发生.我需要 server = FALSE 的原因是没有这个,该应用程序仅下载文件夹的第一页(保存后丢失所有其余数据).

This only happens after I add the argument server=FALSE in the renderDT function. The reason I need server=FALSE is without this, the app only download the first page of the folder (missing all the rest of data after saving).

另一个问题是编辑单元格后,如果我选中/取消选中某些列,则编辑后的单元格将恢复其原始值.

Another problem is after I edit a cell, if I check/uncheck some columns, the editted cell goes back to its original value.

有人知道如何解决这些问题吗?

Does anyone know how to fix these issues?

非常感谢.

示例闪亮的应用程序如下:

The example shiny app is below:

library(shiny)
library(DT)
library(dplyr)

shinyApp(
    # UI
    ui = fluidPage(DT::dataTableOutput('tbl'),
                   checkboxGroupInput('datacols', 
                                      label='Select Columns:',
                                      choices= c('Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width', 'Specie'),
                                      selected = c('Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width', 'Specie'),
                                      inline=TRUE )

                   ),

    # SERVER
    server = function(input, output) {



        df = reactiveValues()

        observe ({

            df$dat = iris %>% select(one_of(input$datacols))
        })
        # render DT
        output$tbl = renderDT(server=FALSE, {
                datatable(df$dat,
                editable = "cell",
                extensions = "Buttons",
                options = list(
                    dom = "Bfrtip", buttons = list("csv")))

        })


        observeEvent(input[["tbl_cell_edit"]], {
            cellinfo <- input[["tbl_cell_edit"]]
            df$dat  <- editData(df$dat,  input[["tbl_cell_edit"]], "tbl")
        })

    }
)

推荐答案

这是因为您正在使用 server = FALSE 的代理.你不应该.做

That's because you're using the proxy with server = FALSE. You should not. Do

observeEvent(input[["tbl_cell_edit"]], {
  cellinfo <- input[["tbl_cell_edit"]]
  df$dat <- editData(df$dat,  input[["tbl_cell_edit"]])
})

不是

observeEvent(input[["tbl_cell_edit"]], {
  cellinfo <- input[["tbl_cell_edit"]]
  df$dat <- editData(df$dat,  input[["tbl_cell_edit"]], "tbl")
})

如果要使用 server = TRUE 下载整个表,请参见此讨论.

If you want to download the whole table with server = TRUE, see this discussion.

这篇关于下载已编辑的数据表在闪亮的应用程序中发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆