I would like to create a matrix in which one could insert numeric values. Also, I would like that the number of rows visible depend on an actionButton. The following code herebelow works fine as long as I've got NAs in my matrix, but not if I replace the NA by some numericInput.
Here is the ui.R:
shinyUI(
pageWithSidebar(
headerPanel("test"),
sidebarPanel(
actionButtonGreen("test","add a row")),
mainPanel(
uiOutput("value"))
)
)
And here is the server.R:
shinyServer(function(input,output){
observe({
if (input$test == 0)
return()
isolate({
output$value <-renderTable(
mdat <- matrix(NA, nrow = input$test, ncol = 2, byrow = TRUE)
)
##If I change the NAs to a vector of numericInput, I obtain the following error
##Error: number of items to replace is not a multiple of replacement length
##That's when I replace the NA in the above matrix with
##c(numericInput(inputId="1",label="",value="2"),
## numericInput(inputId="2",label="",value="2"),
## numericInput(inputId="3",label="",value="2"),
## numericInput(inputId="4",label="",value="2"))
})})
} )
Any advice would be greatly appreciated.
Cheers
I wrote these functions to do the same thing. Hope this helps.
This is what you are trying to insert into your matrix (the value of
numericInput(inputId="1",label="",value="2")
) :and this is his structure, it's a list of 2 lists with 3 elements :
Your problem is that the function
numericInput
returns something that cant fit into you matrix.Then I suggest you to use directly the html tag in a data frame, and with the
sanitize.text.function
function to evaluate the HTML tags as is (and not as strings).