Basically, I am creating an App which will have dynamic input. The user will enter the values inside the textInput and then the data will be automatically stored in the datatable.
For Example : Lets say I have to enter name of Items and Quantity I bought from store just onces. The number of items are going to vary. so I need to have dynamic input and also a provision to store it in data format.
library(shiny)
ui <- fluidPage(
numericInput("n", "Number of items", value = 5, min = 1),
uiOutput("col"),
textOutput("text"))
server <- function(input, output, session) {
item_names <- reactive(paste0("item", seq_len(input$n)))
qty <- reactive(paste0("qty", seq_len(input$n)))
strr <- reactive(tribble(~item, ~qty, item_names(), qty()))
output$col<- renderUI({
map2(strr(), ~textInput({..1}, "Item", ""),
textInput({..2}, "Qty", ""))})
output$text<- renderText({
map_chr(item_names(), ~ input[[.x]])})
}
shinyApp(ui, server)
I know the code is quite wrong. Any direction or help is really appreciated.
Thanks