【发布时间】:2020-11-28 14:21:30
【问题描述】:
我正在尝试从闪亮的 DT 输出中获取子集数据表,其中我编辑了一些单元格。 不需要编辑原始数据表,只需渲染编辑的值。 这就是我闪亮的 UI 的外观:
第一个DT是源数据 第二个是用第一行的选定行制作的 和下面的三行是加权平均值;加权标准差;和第二个数据表的总和。
我使第二个 DT 的 col “Poids” 可编辑,我想提取一个带有已编辑(以及其他)DT2 的 DT 也对它进行我的 3 计算。
我的代码有一部分:
x2<-reactive({
sel <- input$x1_rows_selected
if(length(valdureT())){
valdureT()[sel, ]
}
})
output$x2 = DT::renderDataTable(x2(), rownames = FALSE,editable = list(
target = 'cell', disable = list(columns = c(1:9))),
extensions = c ('RowGroup'),
options = list(rowGroup = list(dataSrc = 2), order = list(c(4 , 'asc'))),
selection = 'none'
)
x3<-reactive({
sel <- input$x2_rows_all
if(length(x2())){
x2()[sel, ]
}
})
M<-reactive({M <- x3()$"Dureté Moyenne"
M<-as.numeric(M)})
S<-reactive({S<- x3()$"Ecart Type Dureté"
S<-as.numeric(S)})
N<-reactive({N<- x3()$Poids
N<-as.numeric(N)
})
dureTmoymoy<- reactive({paste("Dureté Moyenne des batchs séléctionnés : ",{weighted.mean(M(), N())}," kg")})
sdmoy<- reactive({paste("Ecart Type des batchs selectionnés : ",{sqrt(weighted.mean(S()^2 + M()^2, N()) - weighted.mean(M(), N())^2)}," kg")})
poidsselect<- reactive({paste("Poids des batchs selectionnés :", {sum(N())}," kg")})
output$dureTmoymoy<-renderText({dureTmoymoy()})
output$sdmoy<-renderText({sdmoy()})
output$poidsselect<-renderText({poidsselect()})
如您所见,我使用输入 $x2_rows_all 制作了 x3 对象(预期的 DT2 (x2),行已编辑),但这不起作用。
这可能吗?
以虹膜数据为例####好吧抱歉有一个虹膜数据的例子。
我使第一列(萼片长度)可编辑;萼片长度对我的加权平均值有影响。
当我编辑萼片长度列时如何让我的 3 条机器人线反应?
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
wellPanel(
fluidRow(
column(12,h2("iris head" , align = "center"), DT::dataTableOutput('x1')),
column(12,h2("row selected on iris head" , align = "center"), DT::dataTableOutput('x2'))
),
h2("3 calculation about 2nd DT with edited cells"),
h3(textOutput("dureTmoymoy", inline = TRUE)),
h3(textOutput("sdmoy", inline = TRUE)),
h3(textOutput("poidsselect", inline = TRUE)),
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
headiris<- reactive({
headiris<-head(iris)
headiris<-as.data.frame(headiris)
})
output$x1 = DT::renderDataTable(headiris())
x2<-reactive({
sel <- input$x1_rows_selected
if(length(headiris())){
headiris()[sel, ]
}
})
output$x2 = DT::renderDataTable(x2(), rownames = FALSE,editable = list(
target = 'cell', disable = list(columns = c(1:6))),
selection = 'none'
)
x3<-reactive({
sel <- input$x2_rows_all
if(length(x2())){
x2()[sel, ]
}
})
M<-reactive({M <- x3()$"Petal.Length"
M<-as.numeric(M)})
S<-reactive({S<- x3()$"Sepal.Width"
S<-as.numeric(S)})
N<-reactive({N<- x3()$"Sepal.Length"
N<-as.numeric(N)
})
dureTmoymoy<- reactive({paste("petal lenght weighted mean ",{weighted.mean(M(), N())}," kg")})
sdmoy<- reactive({paste("sepal width weighted mean (SD) ",{sqrt(weighted.mean(S()^2 + M()^2, N()) - weighted.mean(M(), N())^2)}," kg")})
poidsselect<- reactive({paste("Sepal lenght sum :", {sum(N())}," kg")})
output$dureTmoymoy<-renderText({dureTmoymoy()})
output$sdmoy<-renderText({sdmoy()})
output$poidsselect<-renderText({poidsselect()})
}
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】:
-
请提供一个可重现的示例,带有 UI(和
valdureT等)。 -
现在有一个例子!