停止旋转木马自动播放使用R&#的bplus,闪光和脚本 [英] Stop carousel autoplay using R's bsplus, Shiny and JavaScript

查看:0
本文介绍了停止旋转木马自动播放使用R&#的bplus,闪光和脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用@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的bplus包中的旋转木马。我想停止自动播放。提到了各种解决方案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()中停止,除非鼠标指针悬停在活动幻灯片上。但是,下面的代码演示了可以在shinydashboardPlus包的carousel()中关闭自动播放。

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)
    })
  }
)

这篇关于停止旋转木马自动播放使用R&#的bplus,闪光和脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆