我有一个闪亮的应用程序,我想在主面板中显示文本。但似乎TextOutput不起作用。有没有办法在表之间放置空格线?这是代码。谢谢你的时间
library(DT)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("amountTable", "Amount Tables", 1:10),
actionButton("submit1" ,"Submit", icon("refresh"),
class = "btn btn-primary"),
actionButton("refresh1" ,"Refresh", icon("refresh"),
class = "btn btn-primary")
),
mainPanel(
# UI output
uiOutput("dt")
)
)
)
server <- function(input, output, session) {
global <- reactiveValues(refresh = FALSE)
observe({
if(input$refresh1) isolate(global$refresh <- TRUE)
})
observe({
if(input$submit1) isolate(global$refresh <- FALSE)
})
observeEvent(input$submit1, {
lapply(1:input$amountTable, function(amtTable) {
output[[paste0('T', amtTable)]] <- DT::renderDataTable({
iris[1:amtTable, ]
})
})
})
observe({
lapply(1:input$amountTable, function(j) {
output[[paste0('Text', j)]] <- renderText({
paste0("This is AmountTable", j)
br() ## add space in between the text and table
})
})
})
output$dt <- renderUI({
if(global$refresh) return()
tagList(lapply(1:10, function(i) {
textOutput(paste0('Text', i))
dataTableOutput(paste0('T', i))
}))
})
}
shinyApp(ui, server)
答案 0 :(得分:1)
附件代码适用于我。
library(shiny)
library(DT)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("amountTable", "Amount Tables", 1:10),
actionButton("submit1" ,"Submit", icon("refresh"),
class = "btn btn-primary"),
actionButton("refresh1" ,"Refresh", icon("refresh"),
class = "btn btn-primary")
),
mainPanel(
# UI output
uiOutput("dt")
)
)
)
server <- function(input, output, session) {
global <- reactiveValues(refresh = FALSE)
observe({
if(input$refresh1) isolate(global$refresh <- TRUE)
})
observe({
if(input$submit1) isolate(global$refresh <- FALSE)
})
observeEvent(input$submit1, {
lapply(1:input$amountTable, function(amtTable) {
output[[paste0('T', amtTable)]] <- DT::renderDataTable({
iris[1:amtTable, ]
})
})
})
observeEvent(input$submit1, {
lapply(1:input$amountTable, function(j) {
output[[paste0('Text', j)]] <- renderText({
paste0("This is AmountTable", j)
# br() ## add space in between the text and table
})
})
})
output$dt <- renderUI({
if(global$refresh) return()
tagList(lapply(1:input$amountTable, function(i) {
list(textOutput(paste0('Text', i)),br(),
dataTableOutput(paste0('T', i)))
}))
})
}
shinyApp(ui, server)
请让我知道它解决了您的问题。