目标是创建一个闪亮的应用程序来记录现场数据。观察者通过 selectinput 或 radioGroupButtons 为每个个体记录物种名称、性别和大小(这里限制为 3 个选择)。一个更新按钮,创建一个绑定到反应表的一行数据框。该表显示在应用程序上以检查潜在的输入错误。该表是可编辑的,以允许观察者在发现错误时直接将数据更正到表中。
问题是当我更新一个新条目编辑表时,版本消失了,旧值又回来了,所以我添加了一个 observeEvent 来更改数据框中的值。不幸的是,我得到:“<-: invalid (NULL) left side of assignment". If i replace the value by the exact same value it doesn't return the error but if i change it the error message appears for example replace a "M" by a "F" in the sexe column.
错误ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput(inputId = "sp", label = "sp", choices = c("espece1", "espece2")),
radioGroupButtons(inputId = "sexe", label = "sexe", choices = c("M", "F"), status = "custom-class"),
radioGroupButtons(inputId = "size", label = "size", choices = c("30", "20", "10"), status = "custom-class"),
actionButton("update", "Update Table")
),
mainPanel(
dataTableOutput("table1")
)
)
)
server <- function(input, output, session) {
mydata <- reactiveVal(data.frame(sp = character(),
sexe = character(),
size = character(),
stringsAsFactors = FALSE))
observeEvent(input$update, {
to_add <- data.frame(sp = input$sp,
sexe = input$sexe,
size = input$size)
mydata(rbind(mydata(), to_add))
})
output$table1 <- DT::renderDataTable({
datatable(mydata(), editable = "cell",
options = list(pageLength = 50,
paging = FALSE))
})
observeEvent(input$table1_cell_edit, {
info <- input$table1_cell_edit
row <- info$row
col <- info$col
value <- info$value
mydata()[row,col] <- value
})
}
shinyApp(ui, server)
以下是我的一些尝试:
mydata()\[row,col\] \<\<- isolate(DT::coerceValue(value, mydata()\[row,col\]))
仍然是同样的错误。"Error in \<-: object of type 'closure' is not subsettable"
。
提前感谢您的帮助