Hi Joe
I tried your function to disable my input tags, it works well.
But your this function can only be used to disable the input tags, I tried to alter it to lock the input tags that the user cannot change the input once he locks it.
I just add the condition argument so that when the user click certain actionbutton, the parameter he chose will be locked and cannot be changed, the chose parameter will be used in the following data analysis.
disable <- function(x,condition=T) {
if (condition==T){
if (inherits(x, 'shiny.tag')) {
if (x$name %in% c('input', 'select'))
x$attribs$disabled <- 'disabled'
x$children <- disable(x$children)
}
else if (is.list(x) && length(x) > 0) {
for (i in 1:length(x))
x[[i]] <- disable(x[[i]])
}
}
x
}
My problem is when the input tag is disabled , the default parameter in the input tag will be used, not the one that the user chose.
I don't know if you can understand what I mean, I have a small example below.
If the user choose the the parameter "b" and click the button "lock the parameter", the selected parameter will be refreshed to "a".
I don't know how I should update the function that the chosen parameter can be fixed when disable, can you help me out?
Thanks a lot.
##server.R
library(shiny)
shinyServer(function(input, output,session) {
observe({
output$btn2 <- renderUI ({
disable(selectInput ("btn2", "choose parameter",c("a","b")),condition=isTRUE((input$btn1!=0)))
})
})
})
## ui.R
library(shiny)
shinyUI(basicPage(
actionButton("btn1","Lock the parameter"),
uiOutput('btn2')
)
)