shinyFeedback for shinyMatrix

I would like to use shinyFeedback::feedbackWarning for shinyMatrix::matrixInput, but couldn't get it to work. Please see below for a reproducible example. No warning message is produced when an invalid value is entered into the matrixInput. Does anyone have any suggestions? Thank you very much!

library(shiny)

ui <- fluidPage(
  shinyMatrix::matrixInput(
    "survival",
    "Exponential survival",
    value = matrix(c(0.0309, 0.0533),
                   nrow = 1,
                   dimnames = list(
                     NULL, c("Treatment hazard rate",
                             "Control hazard rate"))
    ),
    inputClass = "numeric",
    rows = list(names=FALSE, extend=FALSE),
    cols = list(names=TRUE, extend=FALSE)
  ),
  textOutput("text"),
)

server <- function(input, output, session) {
  lambda1 <- reactive({
    gam1 = as.numeric(input$survival[,1])
    valid = (gam1 > 0)
    shinyFeedback::feedbackWarning(
      "survival", !valid,
      "Treatment hazard rate must be positive"
    )
    req(valid)
    gam1
  })
  
  lambda2 <- reactive({
    gam2 = as.numeric(input$survival[,2])
    valid = (gam2 > 0)
    shinyFeedback::feedbackWarning(
      "survival", !valid,
      "Control hazard rate must be positive"
    )
    req(valid)
    gam2
  })
  
  output$text <- renderText({
    paste0("Hazard ratio is ", round(lambda1()/lambda2(), 3))
  })
}

shinyApp(ui, server)

This topic was automatically closed 21 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.