Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 带有shinyTable和submitButton的可编辑表格_R_Shiny - Fatal编程技术网

R 带有shinyTable和submitButton的可编辑表格

R 带有shinyTable和submitButton的可编辑表格,r,shiny,R,Shiny,我在一个闪亮的应用程序中有一个。它是可编辑的,但由于应用程序中其他地方的submitButton,编辑内容在按下按钮之前不会保存。如果进行了多个更改并按下按钮,则只保存最后一个更改 我的问题是如何让它保存所有已做的更改? 也许有一种方法可以让我在UI中获取整个表的内容,这样我就可以解决问题了? 还是我最好使用shinysky或其他什么 以下是基于包装示例的可复制示例。您将看到,如果对上表进行两次更改,然后按下按钮,则只有第二次更改会复制到下表 library(shiny) library(shi

我在一个闪亮的应用程序中有一个。它是可编辑的,但由于应用程序中其他地方的submitButton,编辑内容在按下按钮之前不会保存。如果进行了多个更改并按下按钮,则只保存最后一个更改

我的问题是如何让它保存所有已做的更改? 也许有一种方法可以让我在UI中获取整个表的内容,这样我就可以解决问题了? 还是我最好使用shinysky或其他什么

以下是基于包装示例的可复制示例。您将看到,如果对上表进行两次更改,然后按下按钮,则只有第二次更改会复制到下表

library(shiny)
library(shinyTable)

server <- function(input, output, session) {

  rv <- reactiveValues(cachedTbl = NULL)

  output$tbl <- renderHtable({
    if (is.null(input$tbl)){

      #fill table with 0
      tbl <- matrix(0, nrow=3, ncol=3)

      rv$cachedTbl <<- tbl
      print(tbl)
      return(tbl)
    } else{
      rv$cachedTbl <<- input$tbl
      print(input$tbl)
      return(input$tbl)
    }
  })  

  output$tblNonEdit <- renderTable({
    rv$cachedTbl
  })    
}


ui <- shinyUI(pageWithSidebar(

  headerPanel("Simple Shiny Table!"),

  sidebarPanel(
    helpText(HTML("A simple editable matrix with an update button.
                  Shows that only most recent change is saved. 
                  <p>Created using <a href = \"http://github.com/trestletech/shinyTable\">shinyTable</a>."))
  ),

  # Show the simple table
  mainPanel(
    #editable table
    htable("tbl"),
    #update button
    submitButton("apply table edits"),         
    #to show saved edits
    tableOutput("tblNonEdit")
  )
))

shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinyTable)

服务器根据RStudio的Joe Cheng在a上的建议,似乎不建议使用submitButton,这可能会导致疼痛

在这个简单的示例和我的应用程序中,切换到actionButton和isolate相对简单

解决方案如下

library(shiny)
library(shinyTable)

server <- function(input, output, session) {

  rv <- reactiveValues(cachedTbl = NULL)

  output$tbl <- renderHtable({
    if (is.null(input$tbl)){

      #fill table with 0
      tbl <- matrix(0, nrow=3, ncol=3)

      rv$cachedTbl <<- tbl
      return(tbl)
    } else{
      rv$cachedTbl <<- input$tbl
      return(input$tbl)
    }
  })  

  output$tblNonEdit <- renderTable({

    #add dependence on button
    input$actionButtonID

    #isolate the cached table so it only responds when the button is pressed
    isolate({
    rv$cachedTbl
    })
  })    
}


ui <- shinyUI(pageWithSidebar(

  headerPanel("shinyTable with actionButton to apply changes"),

  sidebarPanel(
    helpText(HTML("A simple editable matrix with a functioning update button. 
                   Using actionButton not submitButton. 
                   Make changes to the upper table, press the button and they will appear in the lower. 
                  <p>Created using <a href = \"http://github.com/trestletech/shinyTable\">shinyTable</a>."))
  ),

  # Show the simple table
  mainPanel(
    #editable table
    htable("tbl"),
    #update button
    actionButton("actionButtonID","apply table edits"),
    #to show saved edits
    tableOutput("tblNonEdit")
  )
))

shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinyTable)

也许你可以用Actionbutton来代替?谢谢@pops。我确实试过actionButton,但它把我应用程序的其他地方搞砸了。