I am a beginner in Shiny, and I would like to use values from numeric inputs included in a data table, to update other fields from the same data table.
At this step, it works when the numeric inputs are outside the table, but not when they are included in it. Here is a very simplified version of what I tried, which doesn't work:
This results in only 3 columns. The numeric inputs are indeed included in the table, but I would expect a 4th column, which would contain the values entered in the numeric inputs.
server.fun <- function(input, output) {
observeEvent(input$numInputs, {
output$inputGroup = renderUI({
input_list <- lapply(1:input$numInputs, function(i) {
# for each dynamically generated input, give a different name
inputName <- paste("input", i, sep = "")
numericInput(inputName, inputName,1)
})
do.call(tagList, input_list)
})
})
# this is just a demo to display all the input values
output$inputValues <- DT::renderDataTable({
all <- paste(lapply(1:input$numInputs, function(i) {
inputName <- paste("input", i, sep = "")
input[[inputName]]
}))
matrix = as.matrix(read.table(text=all))
df <- data.frame(matrix)
df$example_vals <- 1:input$numInputs
df$another_col <- rep("A", times = input$numInputs)
df
})
}
ui.R
library(DT)
shinyUI({
sidebarLayout(
sidebarPanel(
numericInput("numInputs", "How many inputs do you want", 4),
# place to hold dynamic inputs
uiOutput("inputGroup")
),
# this is just a demo to show the input values
mainPanel(DT::dataTableOutput("inputValues"))
)
})
Thank you for your answer.
However, maybe I was not clear enough, sorry, but my problem is that I could not manage to incorporate the inputs into the datatable.