如果关闭表格输出,则空格不会消失

时间:2017-03-24 14:55:39

标签: r shiny

我想向用户展示他想要的线条。如果他不想要它,我什么都不显示。

然而,如果我展示了什么,然后什么都没有,表格会消失,但空间仍然存在。还有办法去除空间吗?

非常感谢您的帮助!

可重复的例子

require(shiny)
if (interactive()) {
    ui <- fluidPage(
        column(4,
               selectInput("select", label = h3("How many rows"), 
                           choices = list("0" = 0, "3" = 3, "6" = 6, "9" = 9), 
                           selected = 3)
        ),
        column(8,
               verbatimTextOutput("Warning_1"),
               dataTableOutput("table"),
               verbatimTextOutput("Warning_2"))

    )
    server <- function(input, output) {

        output$Warning_1 <- renderText({
            answer <- paste("We show", input$select, "rows")
        })

        output$Warning_2 <- renderText({
            answer <- paste("As I said we show", input$select, "rows")
        })

        output$table <- renderDataTable({

            if (input$select == "0") {
                return()
            } else {

                dt <- head(mtcars, as.numeric(input$select))
                return(dt)
            }

        },
        options = list(
            lengthMenu = list(c(5, 15, -1), c('5', '15', 'All')),
            pageLength = 15)
        )
    }


    shinyApp(ui = ui, server = server)
}

更新澄清问题:

如果选择显示0行,则标有红叉的空格应该会消失。

This space marked with red cross should disappear if I choose 0 lines to show.

会议信息以防万一:

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.3

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] DT_0.2           data.table_1.9.6 jsonlite_1.1     plotly_4.5.2    
[5] ggplot2_2.1.0    shiny_1.0.0     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.7       magrittr_1.5      munsell_0.4.3     viridisLite_0.1.3
 [5] colorspace_1.2-7  xtable_1.8-2      R6_2.2.0          httr_1.2.1       
 [9] plyr_1.8.4        dplyr_0.5.0       tools_3.3.2       grid_3.3.2       
[13] gtable_0.2.0      DBI_0.5-1         htmltools_0.3.5   yaml_2.1.13      
[17] lazyeval_0.2.0    digest_0.6.10     assertthat_0.1    tibble_1.2       
[21] tidyr_0.6.1       purrr_0.2.2       base64enc_0.1-3   htmlwidgets_0.7  
[25] mime_0.5          labeling_0.3      RevoUtils_10.0.2  scales_0.4.0     
[29] chron_2.3-47      httpuv_1.3.3     
> 

1 个答案:

答案 0 :(得分:1)

这可以通过Criteria,闪亮世界的renderUI来解决。它有点笨拙,但如果你坚持这个功能,这是一个选择。

eval(parse(...))

未选择任何行时折叠:

enter image description here

调用后扩展到所需的空间:

enter image description here