如何向输入矩阵添加列而不收缩r中的矩阵大小?
每当我向矩阵中添加列时,列的宽度都会缩小,直到它们变得太小。有没有办法增加页面的宽度,这样矩阵列就不会收缩?谢谢如何向输入矩阵添加列而不收缩r中的矩阵大小?,r,user-interface,matrix,shiny,user-input,R,User Interface,Matrix,Shiny,User Input,每当我向矩阵中添加列时,列的宽度都会缩小,直到它们变得太小。有没有办法增加页面的宽度,这样矩阵列就不会收缩?谢谢 output$mat <- renderUI({ rw<-list(1:input$numoc) for (i in (1:input$numoc)) { rw[[1]][[i]] = paste("Outcome", i, sep=" ") }
output$mat <- renderUI({
rw<-list(1:input$numoc)
for (i in (1:input$numoc)) {
rw[[1]][[i]] = paste("Outcome", i, sep=" ")
}
clm<-list(1:input$inp1)
for (i in (1:input$inp1)) {
clm[[1]][[i]] = paste("Treatment", i, sep=" ")
}
matrix1 <- matrix(seq(from=1, to=((input$numoc)*(input$inp1)), by=1), input$inp1, input$numoc, dimnames = list(clm[[1]],rw[[1]]))
matrixInput("mat", "Probabilities", matrix1, rows=list(names=TRUE), cols=list(names=TRUE))
})
使用CSS可以输出$mat。一旦我们覆盖了表格布局:固定表的
标题单元格响应最小宽度
属性。您可以根据需要调整最小宽度
确保使用正确的inputID
选择HTML表。在CSS中,ID前面有#
缺点(当然):在某一点上,你会得到一个水平滚动条
library(shiny)
library(shinyMatrix)
# Define UI for application that draws a histogram
ui <- fluidPage(
tags$head(
tags$style(HTML(
"div#mat table {
table-layout: auto;
}
div#mat .matrix-input-col-header-cell div {
min-width: 100px;
}"
))),
# Application title
titlePanel("Min Col Width"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("numoc", "Number of bins:",
min = 1, max = 50, value = 5),
numericInput("inp1", "Inp1", 1)
),
mainPanel(
uiOutput("mat") # show the matrix
)
)
)
# Server as provided by the asker
server <- function(input, output) {
output$mat <- renderUI({
rw <- list(1:input$numoc)
for (i in (1:input$numoc)) {
rw[[1]][[i]] <- paste("Outcome", i, sep = " ")
}
clm <- list(1:input$inp1)
for (i in (1:input$inp1)) {
clm[[1]][[i]] <- paste("Treatment", i, sep = " ")
}
matrix1 <- matrix(seq(from=1, to=((input$numoc)*(input$inp1)), by=1), input$inp1, input$numoc, dimnames = list(clm[[1]],rw[[1]]))
matrixInput("mat", "Probabilities", matrix1, rows=list(names=TRUE), cols=list(names=TRUE))
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinyMatrix)
#为绘制直方图的应用程序定义UI
用户界面,工作完美!谢谢!我想可能有一种方法可以用css覆盖页面宽度,但我不确定该怎么做。谢谢