How to make kable table reactive() in shiny app? Shiny + kable

天大地大妈咪最大 提交于 2020-01-22 19:31:32

问题


I am trying to make kable table reactive and export it in shiny app. already gave a try with renderDataTable/renderTable inside server and output functions as datatableOutput/tableOutput, but of no luck and following is the line of code.

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

tableOutput("tableset")      

回答1:


Since kable returns HTML, you can render your table using htmlOutput in ui and renderText in server:

# UI component
htmlOutput("tableset") 

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

Additionally, if you want to make it responsive to user input, you can wrap it in a reactive expression:

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

# my_table() will call the cached table 

This will be especially helpful if you want to use the same table multiple times. You can check out eventReactive to trigger it with a specific input as well. Please refer here for more information on reactivity in Shiny: https://shiny.rstudio.com/articles/reactivity-overview.html



来源:https://stackoverflow.com/questions/51460955/how-to-make-kable-table-reactive-in-shiny-app-shiny-kable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!