如何在闪亮的应用程序中制作 kable table reactive()?闪亮+电缆
How to make kable table reactive() in shiny app? Shiny + kable
我正在尝试使 kable table 具有反应性并将其导出到闪亮的应用程序中。已经尝试在服务器内部使用 renderDataTable
/renderTable
,输出函数为 datatableOutput
/tableOutput
,但运气不好,下面是代码行。
output$tableset <- renderDataTable({
kable(spread_bole) %>%
kable_styling(font_size = 15 ,bootstrap_options = c("striped","hover", "condensed")) })
tableOutput("tableset")
由于 kable
returns HTML,您可以使用 ui
中的 htmlOutput
和 renderText
中的 table 渲染您的 table 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
如果您想多次使用同一个 table,这将特别有用。您也可以查看 eventReactive
以使用特定输入触发它。有关 Shiny 中反应性的更多信息,请参阅此处:https://shiny.rstudio.com/articles/reactivity-overview.html
您好,我正在寻找相同的东西,我发现 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)
我正在尝试使 kable table 具有反应性并将其导出到闪亮的应用程序中。已经尝试在服务器内部使用 renderDataTable
/renderTable
,输出函数为 datatableOutput
/tableOutput
,但运气不好,下面是代码行。
output$tableset <- renderDataTable({
kable(spread_bole) %>%
kable_styling(font_size = 15 ,bootstrap_options = c("striped","hover", "condensed")) })
tableOutput("tableset")
由于 kable
returns HTML,您可以使用 ui
中的 htmlOutput
和 renderText
中的 table 渲染您的 table 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
如果您想多次使用同一个 table,这将特别有用。您也可以查看 eventReactive
以使用特定输入触发它。有关 Shiny 中反应性的更多信息,请参阅此处:https://shiny.rstudio.com/articles/reactivity-overview.html
您好,我正在寻找相同的东西,我发现 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)