如果文本很长且被省略号隐藏,如何在 R Shiny 中使用带有 virtualSelectInput 的工具提示来显示过滤器值

问题描述 投票:0回答:1

我有一个闪亮的 R 应用程序,其中使用 virtualSelectInput 显示过滤器的值列表。但我的一些文本值很长,保管箱通过省略号隐藏它们(...)。

我看到虚拟选择文档提到使用工具提示来显示这些长值,同时在值选择期间悬停光标。但我找不到在 R Shiny 中使用它的方法。

我还发现 R闪亮有另一个来自同一个shinyWidgets库的名为tooltipOptions的函数,用于显示下拉菜单按钮的工具提示。但同样,没有任何使用示例。

我尝试通过一个虚拟的闪亮应用程序以下面的形式使用它 -

library(shiny)
library(shinyWidgets)

options <- c(
  "This is short text",
  "This is a longer text",
  "This is a very very very very long text",
  "This is a super ultra pro max very very very very long text"
)

ui <- fluidPage(
  titlePanel("Virtual Select Input Example"),
  
  virtualSelectInput("selected_option", "Select Digital Thread:", choices = options, 
                     multiple = TRUE, search = TRUE, searchNormalize = TRUE, position = "auto", dropboxWidth = "250px", 
                     showSelectedOptionsFirst = TRUE, placeholder = "All", markSearchResults = TRUE, selectAllOnlyVisible = TRUE,
                     tooltipOptions = tooltipOptions(placement = "right", title = "Params", html = FALSE)),
  
  textOutput("selected_value")
)

server <- function(input, output, session) {
  output$selected_value <- renderText({
    paste("You selected:", input$selected_option)
  })
}

shinyApp(ui, server)

但这不起作用。我知道我没有正确地将它们一起使用,所以如果有人可以通过这种方式或任何其他简单的方式指导使用它,我将不胜感激。 我不太倾向于使用自定义 css 或 js 代码,因为在我的实际应用程序中,我在几乎 100 个不同的地方有 Virtual Select。

javascript r shiny shinydashboard shinywidgets
1个回答
0
投票

执行此操作的一种选择是将

dropboxWidth
的大小增加到
500px
。然后你就可以得到这样的结果:

ui <- fluidPage(
  titlePanel("Virtual Select Input Example"),
  
  virtualSelectInput("selected_option", "Select Digital Thread:", 
                     choices = options, 
                     multiple = TRUE, 
                     search = TRUE, 
                     searchNormalize = TRUE, 
                     position = "auto", 
                     dropboxWidth = "500px", # Change this parameter
                     showSelectedOptionsFirst = TRUE, 
                     placeholder = "All", 
                     markSearchResults = TRUE, selectAllOnlyVisible = TRUE,
                     tooltipOptions = tooltipOptions(placement = "right", 
                                      title = "Params", html = FALSE)),
  
  textOutput("selected_value")
)

© www.soinside.com 2019 - 2024. All rights reserved.