Question

I am calling the below file.R as a source into my server.R. Here I am trying to select some names and submit, after submission, I want to show the 'Thank you for Submission' message and some gvisTable. My actionButton seems like not working properly. I am sorry, I can not provide the whole code and sample data as this is so big.

    Nomination <- function(){
      {
        fluidRow(column(3, 
                        h4(tags$div(paste0('Nominations'), style='color:blue'),
                           h4(tags$div(textOutput('alert3'), style='color:green')),
                           h4(tags$div(textOutput('alert2'), style='color:red')),
                           selectInput(inputId = "person",label = "Select a Person:", choices = sDF$Name, selected = NULL, multiple=TRUE, selectize=TRUE),
                           br(),br(),
                           uiOutput('nomiButton'),
                           htmlOutput('tableNomi'),
                           tableOutput("values")
                        )))  
      }

      if(input$nominate)
      {
        fluidRow(column(3,
                        h4(tags$div(paste0('Nominations'), style='color:blue'),
                           h4(tags$div(textOutput('alert1'), style='color:red')),
                           htmlOutput('tableNomi')
                        )))

      } 

}


output$nomiButton = renderUI({
    if(length(input$person)>users_list$Number) 
      return(NULL)
    return(actionButton('nominate', 'Nominate'))
})


output$alert1 = renderText({
  return(paste0('Thank you for the Submission'))
})

output$alert2 = renderText({
    totNomi = users_list$Number
    selNomi = length(input$person)
    if(selNomi>totNomi) paste0('Please do not select more than ',totNomi)
})

output$alert3 = renderText({
  totNomi = users_list$Number
  selNomi = length(input$person)
  if(selNomi<totNomi) paste0('Please select ',totNomi - selNomi, ' Nomination(s)')
})

output$tableNomi = renderGvis({
   nominations = sDF[sDF$Name %in% input$person,]
   nominations = unique(nominations, by='Name')
   write.table(nominations,file='collect_data/nominations.csv', append=T, sep=',', col.names=F, row.names=F, eol='\r')
   gvisTable(nominations, options=list(height=1500, width=800))
})
Was it helpful?

Solution

I have changed the logic as below to work

   Nomination <- function(){

      if(input$nominate==2 && !is.null(input$nominate))
      {
        fluidRow(column(3,
                        h4(tags$div(paste0('Nominations'), style='color:blue'),
                           h4(tags$div(textOutput('alert1'), style='color:red')),
                           htmlOutput('tableNomi')
                        )))

      } 
    else {
        fluidRow(column(3, 
                        h4(tags$div(paste0('Nominations'), style='color:blue'),
                           h4(tags$div(textOutput('alert3'), style='color:green')),
                           h4(tags$div(textOutput('alert2'), style='color:red')),
                           selectInput(inputId = "person",label = "Select a Person:", choices = sDF$Name, selected = NULL, multiple=TRUE, selectize=TRUE),
                           br(),br(),
                           uiOutput('nomiButton'),
                           htmlOutput('tableNomi'),
                           tableOutput("values")
                        )))  
      }



}

and

output$nomiButton = renderUI({
    if(length(input$se)>users_list$Number) 
      return(NULL)
    return(shinysky::actionButton('nominate', 'Nominate', styleclass='info', icon='check'))
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top