datatable - R Shiny observeEvent issues -
i trying delete rows dataframe when have been selected in datatable , presses "delete rows" switch. input$click_rows_selected gives id's of selected rows.
there seems wrong use of observeevent , observe, because code deletes selected rows first time flick switch. afterwards however, every time select row deletes row. how stop deleting row once switch has been turned off? if , else statement don't seem @ all.
shortened version of code:
observeevent(input$deleterows,{ if(input$deleterows==true){ observe({ if (is.null(input$click_rows_selected)) return() values$df <- values[input$click_rows_selected,]})} else{ print("check")} })
the following code should toward solution. please note practice have nested observe
should in general avoided.
i've added updatecheckboxgroupinput
thought made sense in context of example.
library(shiny) values <- reactivevalues(df = iris) ui <- fluidpage( sidebarlayout( sidebarpanel( checkboxgroupinput('inputid', label=null, choices = colnames(df), selected = null, inline = false, width = null, choicenames = null, choicevalues = null), actionbutton("deleterows", "push delete") ), mainpanel(tableoutput("contents") ) )) server <- function(input,output,session){ observeevent(input$deleterows,{ cols <- setdiff(colnames(values$df), input$inputid) values$df <- values$df[c(cols)] updatecheckboxgroupinput(session, 'inputid', label = null, choices = colnames(values$df), selected = null, inline = false, choicenames = null, choicevalues = null) }) output$contents <- rendertable({ values$df }) } shinyapp(ui,server)
Comments
Post a Comment