如何在R Shiny中的数据表上实现内联编辑 [英] How to implement inline editing on datatables in R Shiny

查看:1365
本文介绍了如何在R Shiny中的数据表上实现内联编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行R Shiny网络应用程序。我使用数据表显示数据。但是我想要对表的单元格进行内联编辑。我无法做到这一点可以有人指导我吗?



这是我的代码在

  $ UI 
$(
列(4,dataTableOutput(numericBin)),
列(8,h1(numericBin_Chart)))






  #Server.R 

输出$ numericBin< - renderDataTable({
mtcars
},options = list(
lengthChange = FALSE,
searching = FALSE,
autoWidth = TRUE,
paging = FALSE
))

我想编辑单元格。以下是我要执行此操作的链接:

https:/ /editor.datatables.net/examples/inline-editing/simple.html



我需要添加在选项列表中的东西,但是我

解决方案

除了由@dracodoc提出的DT原型之外,另一个选项是使用 rhandsontable package



编辑:根据@hveig和@Munawir的评论,现在附加了一个工作示例代码(从 rhandome示例页面):

  library(闪亮)
库(rhandsontable)

shinyApp(
ShinyUI(
fluidRow(
rHandsontableOutput(hot)
))

ShinyServer(function(input,output,session){
values = reactiveValues()

data = reactive({
if (!is.null(input $ hot)){
DF = hot_to_r(input $ hot)
} else {
if(is.null(values [[DF]]) )
DF = mtcars
else
DF =值[[DF]]
}


值[[DF ]] = DF
DF
})

输出$ hot< - renderRHandsontable({
DF = data()
if(! null(DF))
rhandsontable(DF, chH =all)
})
})


I am running an R Shiny web-app. I used datatables to show the data. But I want the inline editing of cell of the tables. I am unable to do that. Can any one guide me?

Here is my code in

# UI.R

fluidRow(
         column(4,dataTableOutput("numericalBin")),
         column(8,h1("numericalBin_Chart")))
)


# Server.R

output$numericalBin <- renderDataTable({
    mtcars
  },options = list(    
    lengthChange=FALSE,
    searching=FALSE,
    autoWidth=TRUE,
    paging=FALSE
  ))

I want to edit cell. Here is the link I want to do the effect:
https://editor.datatables.net/examples/inline-editing/simple.html

I need something to add in option list maybe but I can not find the right one.

解决方案

Apart from DT prototype proposed by @dracodoc, another option is using rhandsontable package.

EDIT: according to comments by @hveig and @Munawir, a piece of working example code is now attached (adapted from rhandome examples page):

library(shiny)
library(rhandsontable)

shinyApp(
  shinyUI(
    fluidRow(
      rHandsontableOutput("hot")
    )),

  shinyServer(function(input, output, session) {
    values = reactiveValues()

    data = reactive({
      if (!is.null(input$hot)) {
        DF = hot_to_r(input$hot)
      } else {
        if (is.null(values[["DF"]]))
          DF = mtcars
        else
          DF = values[["DF"]]
      }


      values[["DF"]] = DF
      DF
    })

    output$hot <- renderRHandsontable({
      DF = data()
      if (!is.null(DF))
        rhandsontable(DF, stretchH = "all")
    })
  })
)

这篇关于如何在R Shiny中的数据表上实现内联编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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