How to make appear sidebar on hover instead of click in Shiny?

拈花ヽ惹草 提交于 2020-12-07 07:15:45

问题


I am working on a shiny application and have used shinydashboard package for the UI part. I want to open the sidebar on hover instead of click on the button. I have tried data-trigger option but it is not working. Can anyone please help me in doing this?

A minimal example for the shiny dashboard application

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody()
)

server <- function(input, output) { }

shinyApp(ui, server)

回答1:


You can do it with JQuery:

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(),
  tags$head(tags$script(HTML("$(function() { $('a.sidebar-toggle').mouseover(function(e) { $(this).click()})});")))
)

server <- function(input, output) { }

shinyApp(ui, server)


来源:https://stackoverflow.com/questions/59409065/how-to-make-appear-sidebar-on-hover-instead-of-click-in-shiny

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