Issue in action button

The code below has action button in rendered in html. But when i click the button in second row(id as "ang") there is no modal box showing up. Can anyone help me? Not sure why this logic is not working.. If I put a normal button, it is working

library(shiny)
library(shinydashboard)
library(DT)

number_compare <- data.frame(replicate(2, sample(1:100, 10, rep=TRUE)))
# number_compare$direction <- ifelse(
#   number_compare$X1 < number_compare$X2,
#   as.character(icon("angle-up")),
#   as.character(icon("angle-down"))
# )

sidebar <- dashboardSidebar()

body <- dashboardBody(
  fluidRow(box(width = 12, solidHeader = TRUE,
               DTOutput("example_table"))
  )
)

ui <- dashboardPage(dashboardHeader(title = "Example"),
                    sidebar,
                    body
)


server <- function(input, output) {
  
  number_compare$X2[which(rownames(number_compare) == 2)] = paste(with(number_compare, X2[rownames(number_compare) == 2])," ", as.character(actionButton("ang","")))
  number_compare$X2[which(rownames(number_compare) == 4)] = paste(with(number_compare, X2[rownames(number_compare) == 4])," ", as.character(actionButton("angle2","", icon("angle-up"),style = "border: none;
                                                                                                                                                         outline:none;background:white")))
  number_compare$X2[which(rownames(number_compare) == 6)] = paste(with(number_compare, X2[rownames(number_compare) == 6])," ", as.character(actionButton("angle3","", icon("angle-up"),style = "border: none;
                                                                                                                                                         outline:none;background:white")))
 
 
 
  
  output$example_table <- DT::renderDT({
    datatable(
      number_compare,
      escape = FALSE)
   
    
    })
 
  observeEvent(input$ang,{
   
    showModal(modalDialog(
      title = "Somewhat important message",
      "This is a somewhat important message.",
      easyClose = TRUE,
      footer = NULL
    ))
    })
 
  
  
}

shinyApp(ui, server)
 output$example_table <- DT::renderDT({
    datatable(
      number_compare,
      escape = FALSE
    ,options=list(preDrawCallback=JS(
      'function() {
     Shiny.unbindAll(this.api().table().node());}'),
      drawCallback= JS(
        'function(settings) {
       Shiny.bindAll(this.api().table().node());}')))
  })

Thanks a lot the help. It works.

Hi Nir,

Just a small change I did. If i change the input date and click on arrow, it not popping up. Not sure what mistake I am making (Basicall, if I click "sam" button twice, the arrow is not popping up modal box when it is clicked

library(shiny)
library(shinydashboard)
library(DT)

number_compare <- data.frame(replicate(2, sample(1:100, 10, rep=TRUE)))
# number_compare$direction <- ifelse(
#   number_compare$X1 < number_compare$X2,
#   as.character(icon("angle-up")),
#   as.character(icon("angle-down"))
# )

sidebar <- dashboardSidebar()

body <- dashboardBody(
  fluidRow(box(width = 12, solidHeader = TRUE,
               DTOutput("example_table"),
               actionButton("sam","sam"),
               dateInput("da","Date", value = Sys.Date(), min = Sys.Date()-1, max = Sys.Date()+1))
  )
)

ui <- dashboardPage(dashboardHeader(title = "Example"),
                    sidebar,
                    body
)


server <- function(input, output) {
  
  number_compare$X2 <- paste("sd",number_compare$X2)
  
  number_compare$X2[which(rownames(number_compare) == 2)] = paste(with(number_compare, X2[rownames(number_compare) == 2])," ", " ",as.character(actionLink(inputId="ang", label="", icon("caret-up"))))
  
  print(paste(with(number_compare, X2[rownames(number_compare) == 2])," ", as.character(actionButton("ang",""))))
  print("Vinay")
  # number_compare$X2[which(rownames(number_compare) == 4)] = paste(with(number_compare, X2[rownames(number_compare) == 4])," ", as.character(actionButton("angle2","", icon("angle-up"),style = "border: none;
  #   outline:none;background:white")))

  
  
  observeEvent(input$sam,{
    if(input$da == Sys.Date()){
    output$example_table <- DT::renderDT({
      datatable(
        number_compare[c(2,3:4),],
        escape = FALSE
        ,options=list(preDrawCallback=JS(
          'function() {
     Shiny.unbindAll(this.api().table().node());}'),
          drawCallback= JS(
            'function(settings) {
       Shiny.bindAll(this.api().table().node());}')))
    })
    }
    else {
      output$example_table <- DT::renderDT({
        datatable(
          number_compare[c(2,5:10),],
          escape = FALSE
          ,options=list(preDrawCallback=JS(
            'function() {
     Shiny.unbindAll(this.api().table().node());}'),
            drawCallback= JS(
              'function(settings) {
       Shiny.bindAll(this.api().table().node());}')))
      })
    }
  })
  
  # tolisten <- reactive({
  #   list(input$ang, input$da)
  # })
  observeEvent(input$ang,{
    if(!is.null(input$da))
    {
    print("clicked")
    showModal(modalDialog(
          title = "dsd"
    ))
    }
    })
  
  
  
}

shinyApp(ui, server)

you may need to rethink your architecture, as when you throw away a table that had shiny input bindings, and create a new one and try to reuse the bindings without unvinding the old table, you get this sort of problem.
I'd probably prefer to keep the table constant, but update its content, perhaps with DT dataTableProxy

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.