我想根据过滤列表在闪亮的仪表板中动态添加图像轮播。我已经尝试过 shinydashboardPlus 包以及 slickR 包,但似乎无法让它们中的任何一个工作。
尽我所能使用 shinydashboardPlus 重现一个简短的示例。不反对使用其他包。
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(DT)
library(shinyWidgets)
df <- data.frame(
name = c("rose", "carnation", "hydrangea"),
color = c("red", "pink", "blue"),
Picture = c("rose.jpg", "carnation.jpg", "hydrangea.jpg")
)
ui <- dashboardPage(
dashboardHeader(title = "Dynamic Carousel",
titleWidth =300
),
dashboardSidebar(width = 300,
pickerInput(inputId = "color",
label = "Options",
pickerOptions(width = "fit"),
choices = df$color,
selected = df$color,
multiple = TRUE,
options = pickerOptions(actionsBox = TRUE, dropupAuto = FALSE))
),
dashboardBody(
fluidRow(width = 6,
uiOutput("carousel")
),
fluidRow(width = 12,
dataTableOutput("table")
)
)
)
server <- function(input, output) {
filtered <- reactive({
df %>%
filter(color %in% input$color)
})
images <- reactive({
images <- lapply(filtered()$Picture,function(x){
htmltools::tags$img(src = x)
})
return(images)
})
output$carousel <- renderUI({
items = Map(function(i) {carouselItem(
tags$img(src = images()[[i]])
)})
carousel(indicators = TRUE,
id = "carousel",
.list = items
)
})
output$table <- renderDT(filtered())
}
shinyApp(ui = ui, server = server)