0

I'm building a shiny app that will sum population counts by user-defined cut points. could be any number of cut points from 0-100.

my thought is to have the user define the number of age categories they want and then have them enter in the ranges. To do this I installed the package shinyMatrix.

Ideally, I'd like the number of rows in the matrix to be equal to the number of cuts the user defined but this requires a reactive value in the UI function.

ui <- shinyUI(fluidPage(
  sidebarLayout(sidebarPanel(
    numericInput("breaks", "Enter number of age groups", 0, min= 1, max= 100),
    matrixInput("grid", value= matrix(NA,6,2, dimnames = list(NULL, c("lower", "upper"))),
                  rows = list(extend = TRUE),
                  cols = list(names = TRUE)),
    actionButton("calc", "Calculate")
  ),
  mainPanel(
    h4("Population Sum by group"),
    dataTableOutput("table")
  )
  )
))

so where the 6 is in the matrixInput it should be something like output$breaks

app view

1 Answer 1

2

You could use updateMatrixInput on the server side to update the "grid", setting the number of rows equal to input$breaks

  observeEvent(input$breaks, {
    updateMatrixInput(session,inputId = "grid",
                      value = matrix(NA,input$breaks,2,dimnames =list(NULL,c("lower","upper"))))
  })
Sign up to request clarification or add additional context in comments.

2 Comments

brilliant, thank you so much!
Insightful answer @langtang ! How does it work when there are multiple filters applied to the dataset? I posted my question here as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.