根据可编辑单元格用户输入更新闪亮的 DT
Update shiny DT based on editable cells user input
闪亮应用程序的小示例:
library(shiny)
library(tidyverse)
library(DT)
ui <- fluidPage(
# Application title
titlePanel("blah"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
DT::DTOutput('ex_table')
)
)
)
server <- function(input, output) {
output$ex_table <- DT::renderDataTable(mtcars %>% select(cyl) %>% mutate(blah = cyl + 2),
selection = 'none', editable = TRUE)
}
# Run the application
shinyApp(ui = ui, server = server)
如果你 运行 它看起来像:
您可以编辑单元格,因为我在 renderDataTable()
中添加了 editable = TRUE
。
我的 table 提供数据 table 有一行:
mtcars %>% select(cyl) %>% mutate(blah = cyl + 2)
因此特征 'blah' 应该始终是 cyl + 2 中的任何内容。在屏幕截图中我添加了 10,000,因此所需的输出将是数据 table 在命中后更新以显示 10,002输入。
这可能吗?我该怎么做?
您可以关注这些 examples。
尝试:
library(shiny)
library(tidyverse)
library(DT)
ui <- fluidPage(
# Application title
titlePanel("blah"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
DT::DTOutput('modtable'),
)
)
)
server <- function(input, output,session) {
data <- mtcars %>% select(cyl) %>% mutate(blah = cyl + 2)
output$modtable <- DT::renderDT(data, selection = 'none', editable = TRUE)
proxy = dataTableProxy('modtable')
observeEvent(input$modtable_cell_edit, {
info = input$modtable_cell_edit
str(info)
i = info$row
j = info$col
v = info$value
data <<- editData(data, info)
if(j==1){data[i,j+1]<<-as.numeric(data[i,j])+2}
replaceData(proxy, data, resetPaging = FALSE)
})
}
# Run the application
shinyApp(ui = ui, server = server)
闪亮应用程序的小示例:
library(shiny)
library(tidyverse)
library(DT)
ui <- fluidPage(
# Application title
titlePanel("blah"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
DT::DTOutput('ex_table')
)
)
)
server <- function(input, output) {
output$ex_table <- DT::renderDataTable(mtcars %>% select(cyl) %>% mutate(blah = cyl + 2),
selection = 'none', editable = TRUE)
}
# Run the application
shinyApp(ui = ui, server = server)
如果你 运行 它看起来像:
您可以编辑单元格,因为我在 renderDataTable()
中添加了 editable = TRUE
。
我的 table 提供数据 table 有一行:
mtcars %>% select(cyl) %>% mutate(blah = cyl + 2)
因此特征 'blah' 应该始终是 cyl + 2 中的任何内容。在屏幕截图中我添加了 10,000,因此所需的输出将是数据 table 在命中后更新以显示 10,002输入。
这可能吗?我该怎么做?
您可以关注这些 examples。
尝试:
library(shiny)
library(tidyverse)
library(DT)
ui <- fluidPage(
# Application title
titlePanel("blah"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
DT::DTOutput('modtable'),
)
)
)
server <- function(input, output,session) {
data <- mtcars %>% select(cyl) %>% mutate(blah = cyl + 2)
output$modtable <- DT::renderDT(data, selection = 'none', editable = TRUE)
proxy = dataTableProxy('modtable')
observeEvent(input$modtable_cell_edit, {
info = input$modtable_cell_edit
str(info)
i = info$row
j = info$col
v = info$value
data <<- editData(data, info)
if(j==1){data[i,j+1]<<-as.numeric(data[i,j])+2}
replaceData(proxy, data, resetPaging = FALSE)
})
}
# Run the application
shinyApp(ui = ui, server = server)