在Shiny应用中删除DT数据表的行 [英] Delete row of DT data table in Shiny app
问题描述
我有一个闪亮的应用程序,可以在DT表中显示数据框数据。在应用程序中,我有一个按钮,单击该按钮后,它将删除所选的行。第一次选择行并单击删除按钮时,它会起作用,但是再次单击后,错误的行将被删除,并且以前删除的行会重新出现。我认为这是因为当我调用 DT :: renderDataTable()
时,它会从csv重新加载数据帧。
I have a shiny app that displays data frame data in a DT table. In the app I have a button that I when clicked will delete the selected rows. It works the first time I select rows and click the delete button but after clicking again the wrong rows are deleted and any previously deleted rows reappear. I'm assuming this is because it reloads the data frame (from a csv) when I call DT::renderDataTable()
.
从数据框中删除选定的行后如何重新呈现表?
How can I re render the table after deleting a selected row from the the data frame?
推荐答案
这可以帮助您入门:
ui.R
library(shiny)
library(DT)
shinyUI(fluidPage(
titlePanel("Delete rows with DT"),
sidebarLayout(
sidebarPanel(
actionButton("deleteRows", "Delete Rows")
),
mainPanel(
dataTableOutput("table1")
)
)
))
server.R
library(shiny)
library(DT)
library(dplyr)
df <- data.frame(x = 1:10, y = letters[1:10])
shinyServer(function(input, output) {
values <- reactiveValues(dfWorking = df)
observeEvent(input$deleteRows,{
if (!is.null(input$table1_rows_selected)) {
values$dfWorking <- values$dfWorking[-as.numeric(input$table1_rows_selected),]
}
})
output$table1 <- renderDataTable({
values$dfWorking
})
})
这篇关于在Shiny应用中删除DT数据表的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!