我尝试在我的简单应用程序中使用shinyBS
包。我要做的是根据每个radioButton来创建反应性工具提示文本。
为了澄清我的问题,我在HTML & JS中编写了一个简单的代码。
我还发现了一个solution似乎可以解决我的问题,但实际上我认为它不能正常工作。是否可以使用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)
最佳答案
您绝对可以使用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)