【发布时间】:2017-10-11 10:03:31
【问题描述】:
我正在开发 Shiny 应用程序,但无法对动态创建的 textInput 中输入的值求和。 使用的RCode如下:
ui <- fluidPage(
fluidRow(
column(3, offset = 3,wellPanel(textOutput("text2"))),
column(3,wellPanel(textOutput("text3"))),
column(3,wellPanel(textOutput("text4")))
)
)
server <- function(input, output, session){
observeEvent(input$view, {
output$inputGroup = renderUI({
#code for generating textBoxes and corresponding Id's dynamically
input_list <- lapply(1:(nrow(df())*3), function(i) {
inputName <- paste("id", i, sep = "")
textInputRow<-function (inputId,value)
{
textAreaInput(inputName,"", width = "200px", height = "43px", resize = "horizontal")
}
column(4,
textInputRow(inputName, "")
)
})
do.call(tagList, input_list)
})
})
#code for adding the values and displaying the sum
output$text2 <- renderText({
tot = nrow(df())*3
sum1 = 0
for(lim in 1:tot){
if(lim %% 3 == 1){
inp = paste("id",lim)
sum1 = sum1 + input[[inp]]
}
}
})
}
shinyApp(ui = ui, server = server)
谁能帮我处理这段代码?
【问题讨论】:
-
您面临的错误或障碍是什么。您能否修改您的代码以使其可重现?
-
问题是文本框和相应的 InputId 是动态生成的。我想对 InputId 满足条件的文本框求和(最后一个“if”条件,其中 lim 是总数,比如 18。)并在 TextOutput 中显示总和。 @amrrs