I am developing an app in Shiny and I got stuck in summing the values entered in dynamically created textBox. I want to know how to access the value entered in dynamically created textBox.
The RCode used is as follows:
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)
Can anyone help me with this code? Thanks in advance..
I changed summing function and how are the
textAreaInput
are generated too, have a look