gpt4 book ai didi

javascript - R Shiny 工具提示用于 pickerInput Shiny js

转载 作者:行者123 更新时间:2023-12-02 22:43:33 25 4
gpt4 key购买 nike

我正在尝试添加工具提示来选择输入内容。我希望将 txt 向量作为与悬停输入相对应的工具提示。

Javascript 代码不是 fontionnal,但这是我的草稿:

library(shiny)
library(shinyjs)
library(shinyWidgets)

if (interactive()) {

ui <- fluidPage(
useShinyjs(),
extendShinyjs(text = '
shinyjs.selectInput_tooltips = function(id, tooltips){
var selectiInput = $("#"+id).closest("div").find(".dropdown-menu").get(0);
var element_selectInput = selectiInput.childNodes;
for(var i = 0; i< element_selectInput.length; i++){
element_selectInput[i].title = tooltips[i];
}
};
'),
uiOutput("picker")

)
server <- function(input, output) {
output$picker <- renderUI({
txt <- c("Explanation 1", "Explanation 2", "Explanation 3")
tagList(
pickerInput(inputId = "id", label = "Value :", choices = c("num1" = 1, "num2" = 2, "num3" = 3)),
js$selectInput_tooltips("id", txt)
)
})
}
shinyApp(ui, server)
}

任何其他方式都可以接受,并且非常感谢任何帮助。

非常感谢。

最佳答案

您可以看到 extendShinyjs 的第三个示例使用带有多个参数的函数!

library(shiny)
library(shinyjs)
library(shinyWidgets)

txt <- c("Explanation 1", "Explanation 2", "Explanation 3")
ui <- fluidPage(
useShinyjs(),
extendShinyjs(text = '
shinyjs.selectInput_tooltips = function(params){

var defaultParams = {
id : null,
tooltips : null
};
params = shinyjs.getParams(params, defaultParams);

var selectInput = $("#"+params.id).closest("div").find(".dropdown-menu").get(1);
var element_selectInput = selectInput.childNodes;

if(element_selectInput.length >0 && element_selectInput[0].title == ""){ // to be trigger only once
for(var i = 0; i< element_selectInput.length; i++){
element_selectInput[i].title = params.tooltips[i];
}
}

};
'),
pickerInput(inputId = "id", label = "Value :", choices = c("num1" = 1, "num2" = 2, "num3" = 3))

)
server <- function(input, output) {
# throw your function when you click on pickerInput
# Use this because if you don't click on it, the function couldn't work !
# because choices of pickerInput doesn't exist yet
onclick("id" ,js$selectInput_tooltips("id",txt))
}
shinyApp(ui, server)

关于javascript - R Shiny 工具提示用于 pickerInput Shiny js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58505487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com