reactive tooltipBS in shiny using ShinyBS

会有一股神秘感。 提交于 2019-12-01 10:42:49

问题


I try to use shinyBS package into my simple app. What I want to do is to create reactive tooltip text depends on each radioButton.

In order to clarify my problem I wrote a simple code in HTML & JS.

I also found one solution which seemed to solve my issue, but actually I do not think it works properly. Is it possible to do it using shinyBS package?

I also want to implement my HTML & JS code into Shiny but still it does not work.

library(shiny)

yourStr <-   "$(document).ready(function(){
                      $('[id='radio_venue_1']').tooltip({
                                placement: 'right',
                                title: 'Button 1 Explanation',
                                trigger: 'hover'
                                });

                      $('[id='radio_venue_2']').tooltip({
                                placement: 'right',
                                title: 'Button 2 Explanation',
                                trigger: 'hover'
                                });

                      $('[id='radio_venue_3']').tooltip({
                                placement: 'right',
                                title: 'Button 3 Explanation',
                                trigger: 'hover'
                                });
                                });
"

ui <- shinyUI(

  fluidPage(
    fluidRow(
      column(3,
             HTML("<div class='container'><br>
                  <h1>Test</h1>
                  <div>
                  <label id='radio_venue_1'> 
                  <input type='radio' value='1' role='button'> button 1 
                  </label>
                  </div>
                  <div>
                  <label id='radio_venue_2'>
                  <input type='radio' value='2' role='button'> button 2
                  </label>
                  </div>
                  <div>
                  <label id='radio_venue_3'>
                  <input type='radio' value='3' role='button'> button 3
                  </label>
                  </div>
                  </div>")
      ), 
      column(9,
             'Plot')
      ),
  tags$script(HTML(yourStr))
    )
  )

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

}

shinyApp(ui = ui, server = server)

回答1:


You can definitely do this with shinyBS package

rm(list = ls())
library(shiny)
library(shinyBS)

ui <- shinyUI(
  fluidPage(
    fluidRow(
      column(3,
             HTML("<div class='container'><br>
                  <h1>Test</h1>
                  <div>
                  <label id='radio_venue_1'> 
                  <input type='radio' value='1' role='button'> button 1 
                  </label>
                  </div>
                  <div>
                  <label id='radio_venue_2'>
                  <input type='radio' value='2' role='button'> button 2
                  </label>
                  </div>
                  <div>
                  <label id='radio_venue_3'>
                  <input type='radio' value='3' role='button'> button 3
                  </label>
                  </div>
                  </div>")), 
      bsTooltip(id = "radio_venue_1", title = "Button 1 Explanation", placement = "right", trigger = "hover"),
      bsTooltip(id = "radio_venue_2", title = "Button 2 Explanation", placement = "right", trigger = "hover"),
      bsTooltip(id = "radio_venue_3", title = "Button 3 Explanation", placement = "right", trigger = "hover"),
      column(9,'Plot')
      )
    )
  )

server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)



来源:https://stackoverflow.com/questions/34980348/reactive-tooltipbs-in-shiny-using-shinybs

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