【发布时间】:2020-12-13 11:41:43
【问题描述】:
我怎样才能为我的example_2 生成一个子表tableOutput (table_2),其输出来自selectInput 函数,该函数是从example_1 动态创建的。目前 tableOutput 的格式为[1] "" [1] ""。我还不能以类似于我的table_1 的方式以任何方式对其进行子集化。感谢您的帮助。
library(shinythemes)
library(shiny)
#rm(list = ls())
ui <- navbarPage('Example',id = "inTabset",
tabPanel(title = "Example_1", value = "Example_1",
fluidPage(
tags$b( h4("Example_1", align = "left")),
theme = shinytheme("paper"),
fluidRow(
column(6,checkboxGroupInput("checkGroup", label ="",
choices = c(1,2,3,4,5,6,7,8),
selected = c(1,4,7)) )
),
br()
),
hr(),
verbatimTextOutput("example1")
),
tabPanel(title = "Example_2", value = "Example_2",
fluidPage(
tags$b( h4("Example_2", align = "left")),
br(),
fluidRow(
column(4, uiOutput("VarsInput")),
fluidRow(verbatimTextOutput("dataInfo")),
br(),
hr(),
verbatimTextOutput("example2"),
tableOutput("table_1"),
tableOutput("table_2")
))
))
server <- function(input, output, session) {
output$example1 = renderPrint(input$checkGroup)
output$example2 <- renderPrint(
for (i in input$checkGroup) {
print(input[[i]])
}
)
K <- reactive({
length(input$checkGroup)
})
output$VarsInput <- renderUI({
NoV = K()
C = sapply(1:(ceiling(NoV)), function(i){paste0(input$checkGroup[i])})
output = tagList()
for(i in seq_along(1:ceiling(NoV))){
output[[i]] = tagList()
output[[i]] = selectInput(C[i], C[i], c("",c("a","b","c","d","e","f")))
}
output
})
# Table 1 ---------------------------------------------------------------
table_1 <- reactive({
table_1 = input$checkGroup
table_1 = table_1[-3]
table_1
})
output$table_1 = renderTable(table_1())
# Table 2 -----------------------------------------------------------------
table_2 = renderPrint(
for (i in input$checkGroup) {
print(input[[i]])
}
) # What 'input' value will allow me to produce a subsettable table?
output$table_2 = renderTable(table_2())
}
shinyApp(ui, server)
【问题讨论】: