gpt4 book ai didi

javascript - 使用 R 的 bsplus、Shiny 和 JavaScript 停止轮播自动播放

转载 作者:行者123 更新时间:2023-12-04 03:44:10 31 4
gpt4 key购买 nike

使用@YBS 建议将“bs_carousel(...) 放入 renderUI”
这是我的尝试。幻灯片渲染和自动播放一开始是关闭的。但是,单击右侧的 V 形符号并开始自动播放。

library("shiny")
library("shinyjs")
library("bsplus")

# Stop autoplay
# https://stackoverflow.com/questions/26133618/how-to-stop-bootstrap-carousel-from-autosliding

jscode <- "
shinyjs.init = function() {
$('.carousel').carousel({ interval: false });
}"

ui <- fluidPage(

shinyjs::useShinyjs(),
extendShinyjs(text = jscode, functions = c()),

# Application title
titlePanel("Carousel Demo"),

uiOutput("carousel")
)

server <- shinyServer(function(input, output) {
output$carousel <- renderUI({
bs_carousel(id = "images", use_indicators = TRUE) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=Merry")
) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=Christmas")
) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=To")
) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=All")
)
})

})

# Run the application
shinyApp(ui = ui, server = server)
原始问题
我正在使用 R 的 bsplus 包中的轮播。我想停止自动播放。已经提到了各种解决方案 here .
我正在尝试在下面实现其中之一,但没有成功。
library("shiny")
library("bsplus")

# Stop autoplay
# https://stackoverflow.com/questions/26133618/how-to-stop-bootstrap-carousel-from-autosliding

jscode <- "
shinyjs.init = function() {
$('.carousel').carousel({ interval: false });
}"

ui <- shinyUI(fluidPage(

shinyjs::useShinyjs(),
extendShinyjs(text = jscode, functions = c()),

# Application title
titlePanel("Carousel Demo"),
),

bs_carousel(id = "images", use_indicators = TRUE) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=Merry")
) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=Christmas")
) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=To")
) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=All")
)

)

server <- shinyServer(function(input, output) {

})

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

最佳答案

不知何故,自动播放不会在 bs_carousel() 中停止,除非鼠标指针悬停在事件幻灯片上。但是,下面的代码演示了可以在 carousel() 中关闭自动播放。来自 shinydashboardPlus包裹。

library(shiny)
library(shinydashboardPlus)
library(DT)

jscode <-"
$(document).ready(function(){
$('#mycarousel').carousel( { interval: false } );
});"

shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
tags$head(
tags$style(HTML("
#mycarousel {
width:900px;
height:600px;
}
.carousel-control{
color:#FF0000;
}
"))
),
tags$head(tags$script(HTML(jscode))),
carousel(
id = "mycarousel",
carouselItem(
DTOutput("show_iris_dt")
),
carouselItem(
caption = "An image file",
tags$img(src = "YBS.png")
),
carouselItem(
caption = "Item 3",
tags$img(src = "http://placehold.it/900x500/39CCCC/ffffff&text=Happy+New+Year")
)
)
),
title = "Carousel Demo"
),
server = function(input, output) {
output$show_iris_dt <- renderDT({
datatable(iris)
})
}
)

关于javascript - 使用 R 的 bsplus、Shiny 和 JavaScript 停止轮播自动播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65452688/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com