【问题标题】:Show box only when tableoutput is ready in shiny app仅在闪亮的应用程序中准备好表格输出时才显示框
【发布时间】:2019-11-04 01:38:16
【问题描述】:

我想围绕我的 DT-Output 生成一个 boxPlus。现在当我启动我的APP时,盒子的框架已经在那里了。如何管理该框仅在表格输出完成时显示?作为输入,我使用文本输入。

在我的 UI 中我用于输入:

textInput("name", "Insert Number:")

我创建的最后一个盒子:

uiOutput("box")

在服务器端我做:

output$name <- renderText(input$name)

  New_input <- reactive({
    list(input$name)
  })

我创建的盒子是这样的:

output$box <- renderUI({
    boxPlus(
      div(style = 'overflow-x: scroll;'), dataTableOutput("table")
    )

  })

我尝试过:Similar Problem,但我无法解决问题。没有盒子一切正常。

【问题讨论】:

  • 请提供完整的reproducible example
  • 你看到我的回答了吗?它解决了你的问题吗?

标签: r shiny


【解决方案1】:

切勿在 renderText 函数中使用反应式表达式。

您必须将 tagList 包裹在您的两个元素周围才能返回 SINGLE 元素(在您的情况下为列表)。

这是一个可复制的例子。

library(shiny)
library(shinydashboardPlus)
library(dplyr)


# Define UI for application that draws a histogram
ui <- fluidPage(

    # Application title
    titlePanel("Hide box"),

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(
            textInput("name", "Insert Number to filter cyl:")
        ),
        mainPanel(
           uiOutput("box")
        )
    )
)

server <- function(input, output) {

        resultdf <- reactive({
            mtcars %>%
                filter(cyl > input$name)
        })


        output$box <- renderUI({

            output$table <- renderDataTable({
                resultdf()
            })

            if(input$name == "") {
                 return(NULL)
            } else {
                return(
                    tagList(
                        boxPlus(
                            div(style = 'overflow-x: scroll;'), dataTableOutput("table")
                        )
                    )
                  )
                }
        })
}

# Run the application 
shinyApp(ui = ui, server = server)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-13
    • 2018-11-09
    • 2014-04-11
    • 1970-01-01
    相关资源
    最近更新 更多