根据可编辑单元格用户输入更新闪亮的DT [英] Update shiny DT based on editable cells user input
本文介绍了根据可编辑单元格用户输入更新闪亮的DT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个闪亮的小应用程序示例:
库(发光)图书馆(tidyverse)图书馆(DT)ui<-fluidPage(#应用标题titlePanel("blah"),sidebarLayout(sidebarPanel(slideInput("bins",箱数:",最小值= 1最大值= 50值= 30)),#显示生成的分布图mainPanel(DT :: DTOutput('ex_table'))))服务器<-功能(输入,输出){输出$ ex_table<-DT :: renderDataTable(mtcars%&%; select(cyl)%>%mutate(blah = cyl + 2),选择=无",可编辑= TRUE)}#运行应用程序ShinyApp(ui = ui,服务器=服务器)
如果您运行它,它看起来像:
由于我在 renderDataTable()
中添加了 editable = TRUE
,因此可以编辑单元格.
提供数据表的表的行如下:
mtcars%>%select(cyl)%>%mutate(blah = cyl + 2)
因此功能'blah'应该总是cyl + 2中的值.在屏幕快照中,我添加了10,000,因此所需的输出将是数据表的数据更新,在按Enter键后显示为10,002.
这可能吗?我该怎么办?
解决方案
您可以按照以下
A small example shiny app:
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)
If you run that it looks like:
You can edit the cells since I added editable = TRUE
within renderDataTable()
.
My table that feeds the datatable has the line:
mtcars %>% select(cyl) %>% mutate(blah = cyl + 2)
So feature 'blah' should always be whatever is in cyl + 2. In the screen shot I added 10,000, so desired output would be for the datatable to update to show 10,002 after hitting enter.
Is this possible? How can I do this?
解决方案
You could follow these examples.
Try :
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)
这篇关于根据可编辑单元格用户输入更新闪亮的DT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文