【发布时间】:2014-10-29 16:33:53
【问题描述】:
我在一个闪亮的应用程序中有一个shinyTable。它是可编辑的,但由于应用程序中的其他地方有 submitButton,因此在按下按钮之前不会保存编辑。如果进行了多次更改并按下按钮,则仅保存最后一次更改。
我的问题是如何让它保存所做的所有更改? 也许有一种方法可以让我在 UI 中获取整个表格的内容,以便我可以解决? 还是我最好使用shinysky 或其他东西?
以下是基于包中示例的可重现示例。您会看到,如果您对上表进行 2 次更改,然后按下按钮,则只有第 2 次更改会被复制到下表。
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)
感谢您的宝贵时间。 安迪
【问题讨论】:
-
也许您可以使用 Actionbutton 代替?
-
谢谢@pops。我确实尝试过 actionButton,但它弄乱了我应用中其他地方的东西。