Hide and Show button defined by function in module

@winston.
Thank you for your response to my previous question. I could not reply in the right place because upon pressing the reply button I do not get an empty editor, but the posting.

There is another problem I do not how to solve. Please see code below. I would like for the addRmBtnUI("addRm") button to be hidden until it can be unhidden afterwards. I know how to use shinyjs::show(""), but it does not seem to apply in this case because addRmBtnUI is a function in the module. How could I hide the button the function defines and display it later after " textInput("moreThanOneSelected", label = h5(strong("Enter a value to designate combined set", value = "", width = '300px')))),
verbatimTextOutput("manySelected")," has executed?


  textInput("moreThanOneSelected", label = h5(strong("Enter a value to designate combined set", value = "", width = '300px')))),
    verbatimTextOutput("manySelected"),
    hidden(
    addRmBtnUI("addRm")),
     hidden(
    textInput("a", label = "Enter a value to designate combined set. To delete set, please press the REMOVE        button", value = "", width = '300px')),
    verbatimTextOutput("nameOfSet"),
 verbatimTextOutput("text", placeholder = TRUE),


)

library(shiny)

firstUI <- function(id) { uiOutput(NS(id, "first")) }

firstServer <- function(input, output, session, val){#, a) {
ns = session$ns

returnedValue = NULL

output$first <- renderUI({

   # selectInput(ns("select"), h4("Select"), paste0(isolate(a()), letters[1:4]))
   selectInput(ns("select"), h5(strong("PLEASE CHOSE FILES TO COMBINE. IF YOU WANT TO MAKE MORE SETS, PLEASE PRESS THE ADD BUTTON TO DISPLAY FILES. To undo selection select the selected file again and press delete")),c(Choose='', list.files("~/Development/fileTest/GLYCOUNT/DATA")), multiple=TRUE, selectize=TRUE)

})

res <- reactive({

if (length(input$select) > 1) {

paste0(input$select)

#} else {
 # ""

}

})

returnedValue <- reactive({paste0(input$select)})
return(returnedValue)
}

removeFirstUI <- function(id) {
removeUI(selector = paste0('#', NS(id, "first")))
}

addRmBtnUI <- function(id) {
ns <- NS(id)
tags$div(
actionButton(inputId = ns('insertParamBtn'), label = "Add"),
actionButton(ns('removeParamBtn'), label = "Remove"),
hr(),
tags$div(id = ns('placeholder'))
)
}

addRmBtnServer <- function(input, output, session, moduleToReplicate, ...) {
ns = session$ns
params <- reactiveValues(btn = 0, inputFiles = list())
observeEvent(input$insertParamBtn, {
params$btn <- params$btn + 1
params$inputFiles[[params$btn]] <- callModule(moduleToReplicate$server, id = params$btn, ...)
if(moduleToReplicate[[val]] > 1)
insertUI(
selector = paste0('#', ns('placeholder')),
ui = moduleToReplicate$ui(ns(params$btn))
)
})

observeEvent(input$removeParamBtn, {
moduleToReplicate$remover(ns(params$btn))
params$btn <- params$btn - 1
})

return(params)
}


server <- function(input, output, session){

comp <- callModule(
addRmBtnServer, id = "addRm",
  moduleToReplicate = list(
  ui = firstUI,
  server = firstServer,
  remover = removeFirstUI
 )
)


output$nameOfSet <- renderPrint({
  if(comp$btn>0 && length(comp$inputFiles[[comp$btn]]())  > 1)
    shinyjs::show("a")
  else
    shinyjs::hide("a")
  if(comp$btn>0 && length(comp$inputFiles[[comp$btn]]())  > 1 && input$a != "")
   paste(input$a, " --To delete set, plese press the REMOVE button")
})
 output$text <- renderText({
   if(comp$btn>0 && length(comp$inputFiles[[comp$btn]]())  > 1)
       paste(
        "file_name = ", comp$inputFiles[[comp$btn]](),
        "comp = ", comp$btn,
         "set_length = ", length(comp$inputFiles[[comp$btn]]()),
         "set_name = ", input$a
       )
    if(comp$btn > 0 && length(comp$inputFiles[[comp$btn]]())  == 1 )
      paste("Must select more than 1 file.  Please press the add button again and select more than 1 file")
   
   
 })

}

1 Like

A post was merged into an existing topic: How to return value conditionally from module's server function