问题描述
我想让用户选择(已过滤)表的某些行,然后从原始数据中的那些选定行中更改一个值。
请看下面的示例,我几乎在那儿,但是actionButton
更改了一些未选择的行,我不确定为什么。
REPREX :
library(shiny)
library(reactable)
ID <- c("430276","430277","430278","430279","430280","430281","430282","410873")
DATE <- as.Date(c("2021/02/01","2021/02/01","2021/04/01","2020/10/01","2021/05/01","2020/09/01"))
STOP <- c(FALSE,FALSE,TRUE,TRUE)
raw_data <- data.frame(ID,DATE,STOP)
ui <- fluidPage(
titlePanel("Update Table"),sidebarLayout(
sidebarPanel(
uiOutput("idDateRange"),HTML("<br/>"),uiOutput("idStop"),uiOutput("idNoStop")
),mainPanel(
reactableOutput("table")
)
)
)
server <- function(input,output) {
output$idDateRange <- renderUI({
dateRangeInput(
"idDateRange",label = "Date:",min = "2020/09/01",max = "2021/09/01",start = "2020/09/01",end = "2021/09/01",weekstart = 1,separator = "to",format = "dd/M/yyyy"
)
})
output$idStop <- renderUI({
actionButton(
"idStop",label = "STOP"
)
})
output$idNoStop <- renderUI({
actionButton(
"idNoStop",label = "UN-STOP"
)
})
data_filtered <- reactive({
raw_data[raw_data$DATE >= input$idDateRange[1] & raw_data$DATE <= input$idDateRange[2],]
})
output$table <- renderReactable({
reactable(data_filtered(),selection = "multiple",onClick = "select")
})
# This just gets the index of the rows selected by user
table_selected <- reactive(getReactableState("table","selected"))
observeEvent(input$idStop,{
df <- data_filtered()
ind <- table_selected()
df[ind,3] <- TRUE
updateReactable("table",data = df )
# this does not work?
raw_data[raw_data$ID == df$ID,"STOP"] <- TRUE
})
observeEvent(input$idNoStop,3] <- FALSE
updateReactable("table",data = df )
raw_data[raw_data$ID == df$ID,"STOP"] <- FALSE
})
}
shinyApp(ui = ui,server = server)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)