如何在闪亮的应用程序中使Kable Table React()?闪亮+电缆

时间:2018-07-21 23:52:29

标签: r shiny kable kableextra

我正在尝试使kable表具有反应性并将其导出到闪亮的应用程序中。已经尝试在服务器内部使用renderDataTable / renderTable并以datatableOutput / tableOutput的形式输出功能,但是运气不好,下面是代码行。

  output$tableset <- renderDataTable({
kable(spread_bole) %>%
  kable_styling(font_size = 15 ,bootstrap_options = c("striped","hover", "condensed")) })

tableOutput("tableset")      

2 个答案:

答案 0 :(得分:5)

由于kable返回HTML,因此您可以使用htmlOutput中的uirenderText中的server来呈现表格:

# UI component
htmlOutput("tableset") 

# server component
output$tableset <- renderText({
  kable(spread_bole) %>%
    kable_styling(
      font_size = 15,
      bootstrap_options = c("striped", "hover", "condensed")
    ) 
})

此外,如果要使其响应用户输入,则可以将其包装为反应性表达式:

my_table <- reactive({
  kable(spread_bole) %>%
    kable_styling(
      font_size = 15,
      bootstrap_options = c("striped", "hover", "condensed")
    )
})

# my_table() will call the cached table 

如果要多次使用同一张表,这将特别有用。您也可以签出eventReactive来通过特定的输入来触发它。请参阅此处以获取有关Shiny中的反应性的更多信息:https://shiny.rstudio.com/articles/reactivity-overview.html

答案 1 :(得分:0)

您好,我正在寻找相同的内容,我发现 this 可以进行一些更改

library(shiny)
library(tibble)
library(dplyr)
library(kableExtra)

data("mtcars"); head(mtcars,2)
mtcars <- rownames_to_column(mtcars, var="car") %>% head


ui <- fluidPage(
  
  # Application title
  titlePanel("mtcars"),
  
  sidebarLayout(
    sidebarPanel(
      sliderInput("mpg", "mpg Limit",
                  min = 11, max = 33, value = 20)
    ),
    
    mainPanel(
      tableOutput("mtcars_kable")
    )
  )
)

server <- function(input, output) {

  output$mtcars_kable <- function() {
    req(input$mpg)
      mtcars %>%
      #dplyr::mutate(car = rownames(.)) %>% 
      dplyr::select(car, everything()) %>%
      dplyr::filter(mpg <= input$mpg) %>%
      knitr::kable("html") %>%
      kable_styling("striped", full_width = F) %>%
      add_header_above(c(" ", "Group 1" = 5, "Group 2" = 6))
  }
}

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

enter image description here