我有这段代码,我想根据用户输入显示动态数量的表。
我想在同一行中显示它们,例如带有滚动条。
在我当前的版本中,当表格的宽度总和超过12时,它会在不同的行中显示它们。
此外,理想情况下,我希望表的宽度是动态的,因为如果有很多列,则下一个表将覆盖一个表。
可以帮忙吗?
library(shiny)
library(shinydashboard)
library(htmlwidgets)
library(data.table)
ui <- dashboardPage(
skin="blue",
dashboardHeader(
title="sth",
titleWidth = 300),
dashboardSidebar(
width = 300,
sidebarMenu(
menuItem(
"Gathering Information",
tabName = "gatheringinformation",
icon=icon("github")
),
menuItem(
"Sth",
tabName = "Sth",
icon=icon("github")
))),
dashboardBody(
tabItems(
tabItem(tabName = "gatheringinformation",
h2("Gathering Information"),
# 1st row of boxes
fluidRow(
box(
width = 4,
title = "Inputs",
status= "primary",
solidHeader = TRUE,
h5("Please specify the number of alternatives, criteria and experts"),
numericInput("alternatives", h3("Alternatives"),
value = "1"),
numericInput("criteria", h3("Criteria"),
value = "1"),
numericInput("experts", h3("Experts"),
value = "1")
))),
tabItem(tabName = "Sth",
h2("Sth"),
fluidRow(
box(title = "View Data",
width = 12,
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
div(style = 'overflow-x: scroll'),
splitLayout(tableOutput("ratings"))
)
)))))
####################################
############ SERVER ############
####################################
server <- function(input, output, session) {
output$ratings <- renderUI({lapply(1:input$experts,function(j){
column(width=2,
renderTable({
num.inputs.col1 <- paste0(1)
df <- data.frame(num.inputs.col1)
for (m in 1:input$criteria){
for (n in 1:input$alternatives){
df[n,m] <-paste0(1)
}
}
colnames(df) <- paste0("Criteria ",as.numeric(1:input$criteria))
rownames(df) <- paste0("Alternative ",as.numeric(1:input$alternatives))
df
},align = 'c',caption = paste("Expert " ,j), caption.placement = getOption("xtable.caption.placement", "top"), sanitize.text.function = function(x) x))})})
}
# Run the application
shinyApp(ui = ui, server = server)