问题:在下面的应用程序中,我想通过rhandsontable更改并插入新的行到以下数据:
data.frame(car = c("Opel", "Nissan", "Opel", "VW"),
location = c("Ruesselsheim", "Frankreich", "Ruesselsheim", "Wolfsburg"))car == Opel改为car == VW,位置将从Ruesselsheim改为Wolfsburg。car == Opel,那么在提供汽车输入之后,位置应该是Ruesselsheim。
问题:如何有条件地更改单元格值并定义条件默认值?
尝试: hot_col有一个默认参数,但它只接受字符串而不是条件。另外,通过观察者跟踪变化似乎并不是最好的方法。
对如何处理这件事有什么想法吗?非常感谢!
library(shiny)
library(rhandsontable)
ui = shinyUI(fluidPage(
titlePanel("Handsontable"),
sidebarLayout(
sidebarPanel(
rHandsontableOutput("hot")
),
mainPanel(
verbatimTextOutput("debug")
)
)
))
server = function(input, output) {
data <- reactive({
data.frame(car = c("Opel", "Nissan", "Opel", "VW"),
location = c("Ruesselsheim", "Frankreich", "Ruesselsheim", "Wolfsburg"))
})
output$hot <- renderRHandsontable({
DF <- data()
rhandsontable(DF, useTypes = FALSE, selectCallback = TRUE)
})
### DEBUG
output$debug <- renderPrint({
req(input$hot)
input$hot$changes
})
}
shinyApp(ui = ui, server = server)发布于 2020-08-26 11:33:39
可以通过使用reactiveVal和查找表将当前选择合并到:
library(shiny)
library(rhandsontable)
ui = shinyUI(fluidPage(
titlePanel("Handsontable"),
sidebarLayout(
sidebarPanel(
rHandsontableOutput("hot")
),
mainPanel(
verbatimTextOutput("debug")
)
)
))
server = function(input, output) {
LUT_DF <- data.frame(car = c("Opel", "Nissan", "VW"),
location = c("Ruesselsheim", "Frankreich", "Wolfsburg"))
data <- reactiveVal(data.frame(car = c("Opel", "Nissan", "Opel", "VW"),
location = c("Ruesselsheim", "Frankreich", "Ruesselsheim", "Wolfsburg")))
output$hot <- renderRHandsontable({
rhandsontable(data(), useTypes = FALSE, selectCallback = TRUE)
})
observeEvent(input$hot, {
data(merge(LUT_DF, hot_to_r(input$hot)[1], by = "car"))
}, ignoreInit = TRUE)
}
shinyApp(ui = ui, server = server)

https://stackoverflow.com/questions/63594660
复制相似问题