我发现了有关更新数据输出的问题。 脚本如下:
library(shiny)
library(shinyapps)
library(rhandsontable)
## CLIENT SIDE
ui <- shinyUI(pageWithSidebar(
headerPanel("Test of rHandsontable output - hot_to_r function"),
sidebarPanel(
actionButton("goButton", "test rhandsontable")
),
mainPanel(
rHandsontableOutput("all_updates")
,verbatimTextOutput('df_output')
)
))
## SERVER SIDE
server <- shinyServer(function(input, output) {
observeEvent(input$goButton,{
df <- data.frame ( x=1:10
,y=1:10
,z=factor(c("X","P"))
,merge_xy="merger"
)
df[,4] <- paste(df[,1],"+",df[,2])
output$all_updates <- renderRHandsontable({
rhandsontable(df, selectCallback = TRUE, height = 300) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE) %>%
hot_rows(rowHeights = 18)
})
})
observeEvent(input$all_updates,{
zzz <- hot_to_r(input$all_updates)
zzz[,4] <- paste(zzz[,1],'+',zzz[,2],'+',zzz[,3])
#the output of the modified dataframe
print(zzz)
output$all_updates <-renderRHandsontable({
rhandsontable(zzz, selectCallback = TRUE, height = 300) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE) %>%
hot_rows(rowHeights = 18)
})
print(hot_to_r(input$all_updates))
output$df_output <- renderPrint(
print(hot_to_r(input$all_updates))
)
})
output$all_updates <- renderRHandsontable({
df <- data.frame ( x=integer(10)
,y=integer(10)
,z=factor(c("X","P"))
,merge_xy="merger"
)
rhandsontable(df, selectCallback = TRUE, height = 300) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE) %>%
hot_rows(rowHeights = 18)
})
})
shinyApp(ui=ui,server=server)
问题是函数'hot_to_r'从rHandsontable返回数据集,只有一步延迟。
您可以尝试更改Z列:
在列中的任何更改之后,表的输出立即更新,但'hot_to_r'函数的输出生成表的先前版本的快照(没有最新更改)。