【问题标题】:TextOutput not working in shiny RTextOutput 在闪亮的 R 中不起作用
【发布时间】:2017-04-20 15:38:40
【问题描述】:

我有一个闪亮的应用程序,我想在主面板中显示一个文本。但似乎 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)

【问题讨论】:

    标签: r text shiny


    【解决方案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)
    

    请告诉我它可以解决您的问题。

    【讨论】:

      猜你喜欢
      • 2015-06-16
      • 2018-08-02
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      • 2020-02-08
      • 1970-01-01
      • 2021-05-17
      • 2017-10-23
      相关资源
      最近更新 更多