1

我尝试在shinyBS我的简单应用程序中使用包。我想要做的是创建反应式工具提示文本取决于每个单选按钮。

为了澄清我的问题,我用HTML & JS编写了一个简单的代码。

我还找到了一种似乎可以解决我的问题的解决方案,但实际上我认为它不能正常工作。shinyBS是否可以使用包来做到这一点?

我也想将我的 HTML 和 JS 代码实现为 Shiny,但它仍然不起作用。

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

1 回答 1

1

你绝对可以用shinyBS包做到这一点

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)

在此处输入图像描述

于 2016-01-25T07:51:22.247 回答