I have a dynamic UI with to select inputs in order to select the row and column of the data frame and a numeric input for introduce the new number. When I change a number and after I choose another row, shiny changes the number of the new row with the last number used.
server.R
shinyServer(function(input, output) {
output$select1 = renderUI(
selectInput("contrato","Selecciona un codi", c(variables[,1],"Select"), "Select") )
output$select2 = renderUI(
if (is.null(input$contrato) || input$contrato == "Select"){
return()
}else{
selectInput("variable", "Selecciona una variable", c(colnames(variables)[-1], "Select"), "Select")
})
output$select3 = renderUI(
if (is.null(input$variable) || input$variable == "Select" ){
return()
}else{
num <- variables[which(input$contrato == variables$garantias), which(input$variable == colnames(variables))]
numericInput("var", "Modificar:", num)
})
result <- reactive({
if(is.null(input$variable) || is.null(input$contrato) ) {
return()
} else {
variables[which(input$contrato == variables$garantias), which(input$variable == colnames(variables))] <<- as.numeric(input$var)
return(variables)
}
})
output$View = renderTable({
if(is.null(input$contrato) || is.null(input$variable) ) {
return()
} else {
result()
}
})
})
ui.R
shinyUI(fluidPage(
titlePanel("Test"),
sidebarLayout(
sidebarPanel(
uiOutput("select1"),
uiOutput("select2"),
uiOutput("select3")
),
mainPanel(h3("Data frame: "),
tableOutput("View"))
)
))
And the data frame:
variables <- data.frame(garantias = c("C00", "C11", "C22", "C33"), c.retencio = rep(2,4), t.mort = rep(3,4), comi = rep(4,4), desp = rep(5,4), PB = rep(6,4))
Thanks alot!