tabsetPanel / tabPanel R 闪亮的工具提示

时间:2021-06-23 14:04:16

标签: r shiny

我需要向“绘图”、“摘要”和“表格”选项卡添加工具提示。为此,我使用了 bsTooltip 函数。但它在这里不起作用。

library(shiny)
library(shinyBS)
 ui <- fluidPage(
titlePanel("Tabsets"),
sidebarLayout(
conditionalPanel(
'input.dataset === "Plot"',
radioButtons("dist", "Distribution type:",
               c("Normal" = "norm",
                 "Uniform" = "unif",
                 "Log-normal" = "lnorm",
                 "Exponential" = "exp")),br(),
sliderInput("n",
              "Number of observations:",
              value = 500,
              min = 1,
              max = 1000)),
mainPanel(

  tabsetPanel(id = 'dataset',
              tabPanel("Plot", plotOutput("plot")),
              tabPanel("Summary", verbatimTextOutput("summary")),
              tabPanel("Table", tableOutput("table"))))),

   bsTooltip("Plot", "Information", placement = "bottom", trigger = "hover",
      options = NULL),
    bsTooltip("Table", "Table Summary", placement = "bottom", trigger = "hover",
      options = NULL),
    bsTooltip("Summary", "Summary", placement = "bottom", trigger = "hover",
      options = NULL),)


server <- function(input, output) 
     {
     d <- reactive({
dist <- switch(input$dist,
               norm = rnorm,
               unif = runif,
               lnorm = rlnorm,
               exp = rexp,
               rnorm)

dist(input$n)
     })
   output$plot <- renderPlot({
dist <- input$dist
n <- input$n

hist(d(),
     main = paste("r", dist, "(", n, ")", sep = ""),
     col = "#75AADB", border = "white")
     })

      output$summary <- renderPrint({
summary(d())})
    output$table <- renderTable({
d()})}
  shinyApp(ui, server)

如果我将 bsTooltip ID 更改为数据集,它会起作用,但不会像预期的那样

有没有其他方法可以做到这一点?

1 个答案:

答案 0 :(得分:0)

您可能想要使用较新的软件包 {spsComps}。 ShinyBS 已经超过 5 年没有更新了。{spsComps} 还有很多其他功能。查看demo了解详情。

library(shiny)
library(spsComps)
library(magrittr)
ui <- fluidPage(
    titlePanel("Tabsets"),
    sidebarLayout(
        conditionalPanel(
            'input.dataset === "Plot"',
            radioButtons("dist", "Distribution type:",
                         c("Normal" = "norm",
                           "Uniform" = "unif",
                           "Log-normal" = "lnorm",
                           "Exponential" = "exp")),br(),
            sliderInput("n",
                        "Number of observations:",
                        value = 500,
                        min = 1,
                        max = 1000)),
        mainPanel(
            tabsetPanel(id = 'dataset',
                        tabPanel("Plot", 
                                 plotOutput("plot") %>% 
                                     bsTooltip("Information", placement = "bottom")
                        ),
                        tabPanel("Summary", 
                                 verbatimTextOutput("summary") %>% 
                                    bsTooltip("Table Summary", placement = "bottom")
                        ),
                        tabPanel("Table", 
                                 tableOutput("table") %>% 
                                    bsTooltip("Summary", placement = "bottom")
                        )
            )
        )
    )
)


server <- function(input, output) 
{
    d <- reactive({
        dist <- switch(input$dist,
                       norm = rnorm,
                       unif = runif,
                       lnorm = rlnorm,
                       exp = rexp,
                       rnorm)
        
        dist(input$n)
    })
    output$plot <- renderPlot({
        dist <- input$dist
        n <- input$n
        
        hist(d(),
             main = paste("r", dist, "(", n, ")", sep = ""),
             col = "#75AADB", border = "white")
    })
    
    output$summary <- renderPrint({
        summary(d())})
    output$table <- renderTable({
        d()})}
shinyApp(ui, server)