I am working on creating an upper triangular matrix to let the user input the correlation coefficients between correlated dependent variables (e.g., different traits). I was able to achieve this using r package shinyMatrix
(see screenshot). However, this package only supports the whole matrix rather than the upper-triangular matrix. I temporarily put a NA
in the lower-triangular part, but the user can still delete the NA
and enter any number here. I thought about using numericInput
, but can not figure out the solution as the dimension and column/row names of the input matrix are reactive (depends on user). My question is how to create an reactive upper triangular matrix or table (or similar numeric input) here? If this is not applicable, is it possible to fix all lower triangular elements as "NA" (can not be changed by user) using shinyMatrix
? Any suggestions are welcome and appreciated!
Below is a small example code:
library(shiny) library(shinyMatrix) ui <- basicPage( fluidRow(column(6, numericInput("ntrait", "Number of traits", value = 1, min = 1))), fluidRow(column(6, style='padding:0px;', wellPanel(uiOutput("TPhenocor")))) ) server <- shinyServer(function(input, output, session){ output$TPhenocor <- renderUI({ num <- as.integer(input$ntrait) dmat <- diag(num) dmat[lower.tri(dmat)] <- NA switch(num>1, matrixInput( inputId = "ycor", label = "Correlation coefficients matrix", value = dmat, class = "character", cols = list(names = FALSE), rows = list(names = FALSE)), NULL) }) }) shinyApp(ui = ui, server = server)
https://stackoverflow.com/questions/66083711/create-an-upper-triangular-matrix-table-to-collect-correlation-coefficients-from February 07, 2021 at 09:31AM
没有评论:
发表评论