0
votes

I am stuck in a small problem related to shiny/R.

I am reading in a text file and displaying selective column names returned by grep search into the shiny application on the fly. For this, I am using the dynamicUI.

After the file is read in, the following function runs in server.R. It checks for specific colnames and displays this on the UI using uiOutput. Whatever column names are selected by the user, they are sent to another function for data processing and the plot it returned on the mainPanel.

server.R

    output$Bait <- renderUI({
      data <- input.data();
      if(is.null(data)) return()
       colnames <- names(data)
       colnames = colnames[grep("*LFQ*",colnames,ignore.case=TRUE)]

    # Creating the checkboxes using the above colnames
    checkboxGroupInput("bait", "Choose Bait LFQ columns", 
                        choices  = colnames,
                        selected = colnames)
      })

ui.R

shinyUI(
  sidebarPanel(
    uiOutput("Bait"),
  ),
  mainPanel(
    plotOutput(outputId = 'plot'),
  )
)

Everything is fine, what I am trying to create is an action button for the checkboxes. Some files are big and have a longer list of column names >60, so whenever a checkbox is clicked, the whole function runs for processing and displays a plot. This gets unnecessary when the user has to deselect/select more than 10 columns.

An easy fix is, I kept selected=NULL but what I want is to add an actionButton after the checkboxGroupInput, so that user can select as many as checkBoxes but the function only runs when the GO button is pressed via the actionButton. If add a actionButton control after the checkbocGroupInput, it doesnt' works.

Can someone guide me in this regard. After working on this for sometime, now I am bit lost.

Thanks

1

1 Answers

1
votes

Did you look into ?isolate? Lets say i want function initialFunction() only be evaluated if input$actionButtonis clicked.

observe({
    input$actionButton # everything that triggers initialFunction() should come before isolate()
    isolate({
        # everything that should not trigger initialFunction() should come inside isolate()
        initialFunction()
    })
})