CSS and Shiny modules ( shinyMatrix matrixInput )

Building on this Q&A, I created a modularized version of that code (below).

I have commented lines #39-41. When those lines are uncommented, the padding for the matrixInput is correct (i.e. "auto"):

tags$head(tags$style(HTML(".matrix-input-table td, .matrix-input-table th {height: auto;}")))

However, when those lines are commented, the padding is just too big. How can I correct this in a simple manner? The CSS does not need to be unique for a particular instance of a module.

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyMatrix)

module_matrix_server <- function(id) {
  moduleServer(id,
               function(input, output, session) {
                 return(
                   list(
                     mi = reactive({input$mi})
                   )
                 )
               }
  )
}

module_matrix_ui <- function(id) {
  ns <- NS(id)
  mat_2 <- matrix(rnorm(20), 20, 1)
  rownames(mat_2) <- 1:20
  wellPanel(
    fluidRow(
      column(12,
             matrixInput(ns("mi"), value = mat_2, rows = list(names = TRUE))
      )
    )
  )

}

mat <- matrix(rep("Hide!",9), 3, 3)

ui <- dashboardPagePlus(
  dashboardHeader(),
  sidebar = dashboardSidebar(
    sidebarMenu(
      menuItem("Module 1", tabName = "tab_module_1", icon = icon("calculator", class = "fas", lib = "font-awesome")),
      menuItem("Module 2", tabName = "tab_module_2", icon = icon("calculator", class = "fas", lib = "font-awesome")),
      id = "left_side_bar"
    )#,
    #textInput("tInput","Text",value = "Good!"),
    #shinyMatrix::matrixInput("mInput", value = mat, class = 'character')
  ),
  dashboardBody(
    tags$head(tags$style(HTML(".matrix-input-cell{color: coral;}"))),
    tags$head(tags$style(HTML(".matrix-input-table td, .matrix-input-table th {height: auto;}"))),
    tabItems(
      tabItem(tabName = "tab_module_1",
              boxPlus(
                title = "Matrix input 1",
                status = "primary",
                width = 12,
                collapsible = TRUE,
                closable = FALSE,
                fluidRow(
                  column(6,
                         module_matrix_ui("matrix-input-1")
                  )
                )
              )
      ),
      tabItem(tabName = "tab_module_2",
              boxPlus(
                title = "Matrix input 2",
                status = "primary",
                width = 12,
                collapsible = TRUE,
                closable = FALSE,
                fluidRow(
                  column(6,
                         module_matrix_ui("matrix-input-2")
                  )
                )
              )
      )
    )
  )
)


server <- function(input, output) {
  observe({
    if (req(input$left_side_bar) == "tab_module_1") {
      mms_1 <- module_matrix_server("matrix-input-1")
    }
    if (req(input$left_side_bar) == "tab_module_2") {
      mms_2 <- module_matrix_server("matrix-input-2")
    }
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

This was easily solved by using inlineCSS(), from the shinyjs package, inside the module ui definition.

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.