Entering a binary matrix through checkboxInput's



I am new to shiny and I am stuck with a problem. I want the user to enter a binary matrix through checkboxes - but I don’t get the changes through, i.e. whatever I click in the checkboxes, there is no change in the output.

Here is my code so far:


prbm <- matrix (c(TRUE,FALSE,FALSE,TRUE), 2, 2)

# Define UI ----
ui <- navbarPage("",
             tabPanel("Your Turn",
                      fluidRow(column(5, "Enter your Relation!")),
                                      checkboxInput("pr1", "(1, 1)", prbm[1,1]),
                                      checkboxInput("pr2", "(1, 2)", prbm[1,2])),
                                      checkboxInput("pr3", "(2, 1)", prbm[2,1]),
                                      checkboxInput("pr4", "(2, 2)", prbm[2,2])),
                               column(10, plotOutput("PRplot"), textOutput("value"))

# Define server logic ----
server <- function(input, output) {
  reactive(prbm[2,2] <- input$pr4)
  reactive(prbm[2,1] <- input$pr3)
  reactive(prbm[1,2] <- input$pr2)
  reactive(prbm[1,1] <- input$pr1)
  output$PRplot <- renderPlot({plot(relation(incidence=prbm))})
  output$value <- renderText(as.character(matrix(1*prbm,2,2)))

# Run the app ----
shinyApp(ui = ui, server = server)

Any help is highly appreciated!


I got a bit impatient and asked the question also somewhere else :wink:

Here is the response I got:

The problem in your code is that the renderTable never gets called once you changed the value of pbrm. To do so you can use reactive as shown below:

server <- function(input, output) {
    Tab <- reactive({
      matrix(c(input$pr1, input$pr2, input$pr3, input$pr4), 2,2) 

    output$value <- renderText(1*Tab())

This solved my problem