【发布时间】:2017-10-16 06:20:53
【问题描述】:
我正在 Shiny 中开发一个应用程序,但我陷入了对动态创建的 textBox 中输入的值求和的过程中。我想知道如何访问在动态创建的文本框中输入的值。
使用的RCode如下:
library(shiny)
ui <- fluidPage (
fluidRow(
column(3,numericInput("count", "No. of boxes",value = 4, min = 2, max = 10),
actionButton("View","view")
),
),
fluidRow(
uiOutput("inputGroup")
),
fluidRow(
column(3,wellPanel(textOutput("text3")))
)
)
sum = 0
sumN <- function(x){
sum <- sum + as.numeric(x)
return(sum)
}
server <- function(input, output, session) {
observeEvent(input$view, {
output$inputGroup = renderUI({
input_list <- lapply(1:(input$count), 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)
})
})
getvalues <- reactive({
tot <- input$count
for(lim in 1:tot){
if(lim %% 3 == 1)
val <- reactive({sumN(as.numeric(input[[paste0("id",lim)]]))})
}
})
output$text3 <- renderText({
getvalues()
})
}
shinyApp(ui=ui, server = server)
谁能帮我处理这段代码? 提前谢谢..
【问题讨论】:
标签: r shiny shiny-server