1
我正在Shiny中开发一个应用程序,并且我总结了在动态创建的文本框中输入的值。我想知道如何访问在动态创建的文本框中输入的值。在RShiny中添加动态创建的文本框中的值
使用的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)
谁能帮我这个代码? 在此先感谢..
完美的答案!我只需将sum函数改为:sumN < - function(sum,x)sum
@AntoinePissoort中加入一个条件https://stackoverflow.com/help/someone-answers –
它工作正常!但如果一些值没有输入到文本框中意味着总和没有显示..任何人都可以说解决方案? –