如何使rhandsontable在选择Input后自动重新渲染
我正在开发一个闪亮的应用程序,用户可以将一些数据输入到不同的数据集中,然后用于计算数据集中的其他变量。数据集的选择由selecInput决定。 我选择了rHandsontable,因为它成功地模仿了熟悉的电子表格输入。我将该解决方案用于从中计算柱,并且效果相当好。除了一件小事:在选择不同的数据集之后,rhandsontable不会重新呈现,直到用户与其交互。我明白这是应该发生的,但在我的情况下,我们需要重新渲染。 我尝试过观察、观察和反应的不同组合,但没有任何效果。最接近我的是选择变化的reactiveVal指示器,它至少表明应该使用新数据。 这是我得到的MRE如何使rhandsontable在选择Input后自动重新渲染,r,shiny,rhandsontable,R,Shiny,Rhandsontable,我正在开发一个闪亮的应用程序,用户可以将一些数据输入到不同的数据集中,然后用于计算数据集中的其他变量。数据集的选择由selecInput决定。 我选择了rHandsontable,因为它成功地模仿了熟悉的电子表格输入。我将该解决方案用于从中计算柱,并且效果相当好。除了一件小事:在选择不同的数据集之后,rhandsontable不会重新呈现,直到用户与其交互。我明白这是应该发生的,但在我的情况下,我们需要重新渲染。 我尝试过观察、观察和反应的不同组合,但没有任何效果。最接近我的是选择变化的reac
library(shiny)
library(rhandsontable)
data <- list (
table1 = data.frame( beginning = as.numeric(rep(8, 4)),
ending = as.numeric(rep(15, 4))),
table2 = data.frame( beginning = as.numeric(rep(9, 4)),
ending = as.numeric(rep(17, 4)))
)
data[["table1"]]$hours <- data[["table1"]]$ending - data[["table1"]]$beginning
data[["table2"]]$hours <- data[["table2"]]$ending - data[["table2"]]$beginning
############################# UI #############################
ui = shinyUI(fluidPage(
selectInput("tab", "Chose table: ", choices = list("table1", "table2")),
fluidRow(wellPanel(
column(6,
rHandsontableOutput("hot"),
actionButton(inputId="enter",label="Save")
),
column(6,
textOutput("title"),
tableOutput("tabela")
)))
))
########################## SEREVER ###########################
server=function(input,output, session){
tab_change <- reactiveVal(FALSE)
# rw <- reactivePoll(1000, session, file_name, read.csv2)
react_week <- reactive({
df <- data[[input$tab]]
})
output$title <- renderText(input$tab)
output$tabela <- renderTable(react_week())
observeEvent(input$tab,
{tab_change(TRUE)
})
# Calculation of columns
for_week <- reactive({
datacopy <- NULL
#For initial data upltabd
if(isolate(tab_change()) || is.null(input$hot)) {
datacopy <- react_week()
}
else {
datacopy <- hot_to_r(input$hot)
}
#If there is change in data
if(!is.null(input$hot$changes$changes)){
col.no <- as.numeric(unlist(input$hot$changes$changes)[2])
new.val <- unlist(input$hot$changes$changes)[4]
#If the changed value is prihod or odhod
if(col.no == 0 || col.no == 1){
datacopy[, 3] <- as.numeric(datacopy[, 2]) - as.numeric(datacopy[, 1])
}
}
tab_change(FALSE)
datacopy
})
output$hot <- renderRHandsontable(
rhandsontable(for_week())
)
observeEvent(input$enter, {
data[[input$tab]] <<- hot_to_r(input$hot)
output$tabela <- renderTable( data[[input$tab]])
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(rhandsontable)
数据使用eventReactive
并通过input$tab
和input$hot
触发,而不是reactive
为您的每周reactive对象触发:
library(shiny)
library(rhandsontable)
data <- list (
table1 = data.frame( beginning = as.numeric(rep(8, 4)),
ending = as.numeric(rep(15, 4))),
table2 = data.frame( beginning = as.numeric(rep(9, 4)),
ending = as.numeric(rep(17, 4)))
)
data[["table1"]]$hours <- data[["table1"]]$ending - data[["table1"]]$beginning
data[["table2"]]$hours <- data[["table2"]]$ending - data[["table2"]]$beginning
############################# UI #############################
ui = shinyUI(fluidPage(
selectInput("tab", "Chose table: ", choices = list("table1", "table2")),
fluidRow(wellPanel(
column(6,
rHandsontableOutput("hot"),
actionButton(inputId="enter",label="Save")
),
column(6,
textOutput("title"),
tableOutput("tabela")
)))
))
########################## SEREVER ###########################
server=function(input,output, session){
tab_change <- reactiveVal(FALSE)
# rw <- reactivePoll(1000, session, file_name, read.csv2)
react_week <- reactive({
df <- data[[input$tab]]
})
output$title <- renderText(input$tab)
output$tabela <- renderTable(react_week())
observeEvent(input$tab,
{tab_change(TRUE)
})
# Calculation of columns
# ----------------------------Modified here----------------------------
# for_week <- reactive({
for_week <- eventReactive(c(input$tab, input$hot), {
# ---------------------------------------------------------------------
datacopy <- NULL
#For initial data upltabd
if(isolate(tab_change()) || is.null(input$hot)) {
datacopy <- react_week()
}
else {
datacopy <- hot_to_r(input$hot)
}
#If there is change in data
if(!is.null(input$hot$changes$changes)){
col.no <- as.numeric(unlist(input$hot$changes$changes)[2])
new.val <- unlist(input$hot$changes$changes)[4]
#If the changed value is prihod or odhod
if(col.no == 0 || col.no == 1){
datacopy[, 3] <- as.numeric(datacopy[, 2]) - as.numeric(datacopy[, 1])
}
}
tab_change(FALSE)
datacopy
})
output$hot <- renderRHandsontable(
rhandsontable(for_week())
)
observeEvent(input$enter, {
data[[input$tab]] <<- hot_to_r(input$hot)
output$tabela <- renderTable( data[[input$tab]])
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(rhandsontable)
数据使用eventReactive
并通过input$tab
和input$hot
触发,而不是reactive
为您的每周reactive对象触发:
library(shiny)
library(rhandsontable)
data <- list (
table1 = data.frame( beginning = as.numeric(rep(8, 4)),
ending = as.numeric(rep(15, 4))),
table2 = data.frame( beginning = as.numeric(rep(9, 4)),
ending = as.numeric(rep(17, 4)))
)
data[["table1"]]$hours <- data[["table1"]]$ending - data[["table1"]]$beginning
data[["table2"]]$hours <- data[["table2"]]$ending - data[["table2"]]$beginning
############################# UI #############################
ui = shinyUI(fluidPage(
selectInput("tab", "Chose table: ", choices = list("table1", "table2")),
fluidRow(wellPanel(
column(6,
rHandsontableOutput("hot"),
actionButton(inputId="enter",label="Save")
),
column(6,
textOutput("title"),
tableOutput("tabela")
)))
))
########################## SEREVER ###########################
server=function(input,output, session){
tab_change <- reactiveVal(FALSE)
# rw <- reactivePoll(1000, session, file_name, read.csv2)
react_week <- reactive({
df <- data[[input$tab]]
})
output$title <- renderText(input$tab)
output$tabela <- renderTable(react_week())
observeEvent(input$tab,
{tab_change(TRUE)
})
# Calculation of columns
# ----------------------------Modified here----------------------------
# for_week <- reactive({
for_week <- eventReactive(c(input$tab, input$hot), {
# ---------------------------------------------------------------------
datacopy <- NULL
#For initial data upltabd
if(isolate(tab_change()) || is.null(input$hot)) {
datacopy <- react_week()
}
else {
datacopy <- hot_to_r(input$hot)
}
#If there is change in data
if(!is.null(input$hot$changes$changes)){
col.no <- as.numeric(unlist(input$hot$changes$changes)[2])
new.val <- unlist(input$hot$changes$changes)[4]
#If the changed value is prihod or odhod
if(col.no == 0 || col.no == 1){
datacopy[, 3] <- as.numeric(datacopy[, 2]) - as.numeric(datacopy[, 1])
}
}
tab_change(FALSE)
datacopy
})
output$hot <- renderRHandsontable(
rhandsontable(for_week())
)
observeEvent(input$enter, {
data[[input$tab]] <<- hot_to_r(input$hot)
output$tabela <- renderTable( data[[input$tab]])
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(rhandsontable)
谢谢你,吉姆。我又试了一次(我现在记得早些时候试过),但这打破了计算。看来我还得再找一个事件,它将在一周内激活以进行计算。有什么建议吗?就刷新而言,代码是有效的,但不再进行计算。编辑前两列时,第三列应显示其差异。这在以前是有效的,但在您的解决方案中不再有效。我将输入$hot$changes$changes依赖项添加到了for_week。现在它工作得很好。你能用这个编辑你的答案吗,因为是你让我走上了正确的轨道,所以我可以接受你的答案?我添加了另一个事件input$hot
,看起来效果不错。谢谢@Jim。我又试了一次(我现在记得早些时候试过),但这打破了计算。看来我还得再找一个事件,它将在一周内激活以进行计算。有什么建议吗?就刷新而言,代码是有效的,但不再进行计算。编辑前两列时,第三列应显示其差异。这在以前是有效的,但在您的解决方案中不再有效。我将输入$hot$changes$changes依赖项添加到了for_week。现在它工作得很好。你能用这个编辑你的答案吗,因为是你让我走上了正确的轨道,所以我可以接受你的答案?我添加了另一个事件input$hot
,它似乎工作正常。