【问题标题】:Integrating R outputs in bsplus functions在 bsplus 函数中集成 R 输出
【发布时间】:2018-05-24 09:55:01
【问题描述】:

我认为bsplus 包在开发动态网络时是相关的。我在 Rstudio 中使用 R Markdown。

但是,我发现将 bsplus 函数与 R 输出集成的方式特别棘手。

让我们看一个使用bs_accordion 函数的示例,使用mtcars 数据集

head <- head(mtcars)
tail <- tail(mtcars)

bs_accordion(id ="Data: mtcars") %>%
  bs_append(title = "Head of mtcars", content = head) %>%
  bs_append(title = "Tail of mtcars", content = tail)

我想在手风琴函数中显示 R 输出,显示数据帧 headtail

现在,它只显示head 中的第一个数字行。

是否有可能在bsplus 函数的content 属性中包含R 代码?

通过这种方式,我们能够以动态方式显示 R 结果。

【问题讨论】:

    标签: html r r-markdown accordion bootstrap-accordion


    【解决方案1】:

    这应该适用于您的示例。您必须以某种方式创建数据表,仅包含它不会将其呈现为表。

    注意:我将手风琴的 id 更改为 Data-mtcars。使用空格、“:”或“;”将禁用折叠。

    library(shiny)
    library(bsplus)
    library(DT)
    
    ui <- fluidPage(
      bs_accordion(id ="Data-mtcars") %>%
        bs_set_opts(panel_type = "primary", use_heading_link = T) %>%
        bs_append(title = "Head of mtcars", content = DT::dataTableOutput("table1")) %>%
    
        bs_set_opts(panel_type = "primary", use_heading_link = T) %>%
        bs_append(title = "Tail of mtcars", content = DT::dataTableOutput("table2"))
    )
    
    server <- function(input, output) {
    
      output$table1 <- DT::renderDataTable({
        head
      })  
      output$table2 <- DT::renderDataTable({
        tail
      })
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      • 1970-01-01
      相关资源
      最近更新 更多