我正在使用shinyJS
包,shiny
标签和传统HTML将属性“ title”添加到现有元素。我能够在控制台(检查器[Google CHROME])内完成此操作,但是当尝试通过ui.R或server.R应用相同的输入时,无论是什么都没有改变,或者实际的文本值改变了副标题(工具提示) )。
如上所述,我尝试了以下方法:
shinyJS
:html()
shiny
:标记$ HTML; tags $ body(tags $ script())
HTML:在HTML文件(mychange.html)中添加更改并从www采购
要修改的输入(添加工具提示)
pickerInput(
inputid = "ReqTabSel6",
label = '',
choices = c('Choice 1', 'Choice 2', 'Choice 3'),
mulitple = F,
options = list(
style = "btn-info"))
这是正确的功能(当在Web检查器中在控制台中运行时会更新):
var addToolTip1 = document.querySelector('#form>div:nth-child(10)>div>div>div>ul>li.selected>a')
var att = document.createAttribute("title");
att.value = "I am a tooltip title";
addToolTip1 .setAttributeNode(att);
但是,在R中...
server.R
...
observeEvent(input$ReqTabSel6, {
shinyJS::html(id = NULL,
html = "var addToolTip1 = document.querySelector('#form>div:nth-child(10)>div>div>div>ul>li.selected>a')
var att = document.createAttribute("title");
att.value = "I am a tooltip title";
addToolTip1 .setAttributeNode(att);",
selector = '#form>div:nth-child(10)>div>div>div>ul>li.selected>a')
})
##This updates the actual 'choice' value from 'Choice 1' to 'Choice1I am a tooltip title')
#Changing html to read:
html = 'title = "I am a tooltip title"',
#This replaces the choice (e.g. Choice 1) value so the drop down now has:
I am a tooltip title
Choice 2
Choice 3
要为pickerInput选项的每个子项(选项卡索引)创建工具提示。应该只将“ title”属性添加到指定节点内的其他属性。
答案 0 :(得分:0)
知道了!如果其他用户遇到此问题,请亲自回答。
#server.R
observeEvent(input$actionbutton1,{
shinyjs::html(
html='<a tabindex="0" class=""...title="Your tooltip here"...></a>',
add=FALSE,
selector = '#form>div>form>div>div:nth-child(5)>div>div>div>ul>li:nth-child(4)' #This is the jquerySelector. Note that it will be different for each unique application. You will need to change the 'nth-child(#)' to the specific choice within 'SelectInput' to get a tooltip specific to that choice.)
})