2017-07-06 22 views
0

我還沒有發現在shinyBS文檔和谷歌的/任何信息,以便了解如何上使用trigger = 'manual',例如,shinyBSaddPopover。我認爲這將是向禁用按鈕添加工具提示的方式。 (我不想用div「詠按鈕,並給予titlediv做到這一點。 也將是不錯,如果有人有辦法被動添加工具提示shiny應用添加shinyBS酥料餅上禁用按鈕

+1

請你提供一個可重複的例子。我相信我可以給你一隻手 –

+0

@PorkChop 這個問題有一個答案,有足夠的例子。 Sry我無法回答。我試圖做的事情是在'disabled'按鈕上添加彈出窗口,該按鈕顯示在用鼠標懸停的按鈕上,並在按鈕激活時將其刪除。 –

回答

0

由於shosaco的解決方案沒有工作,我得到它的工作是這樣的:

if (input$disable) { 
    addCssClass("buttonId", "disabled") 
    bsTooltip("buttonId", "This button is currently disabled.") 
} else { 
    bsTooltip("buttonId", "") 
    removeCssClass("buttonId", "disabled") 
} 
observeEvent(input$buttonId, { 
    if (!input$disable) { 
     output$text <- renderText("Bla") 
    } else { 
     output$text <- renderText(NULL) 
    } 
1

如果你想在酥料餅的使用trigger = manual,那麼你需要定義一個腳本來切換酥料餅,如使用jQuery:

library(shiny) 
library(shinyjs) 
library(shinyBS) 


ui <-shinyUI(fluidPage(useShinyjs(), 
         # press this button to trigger the popover 
         actionButton("addPopover", "Add Popover"), 

         # a disabled button 
         disabled(actionButton("disabledButton", "This button is disabled")), 

         # the popover to appear over the disabled button 
         bsPopover("disabledButton", "Popover", "Some text", trigger="manual"), 

         # the script to trigger the popover 
         uiOutput("trigger"))) 


server <- shinyServer(function(input,output, session){ 

    # on checkbox selection, disable button and trigger the popover 
    output$trigger <- renderUI({ 
    input$addPopover 
    tags$script("$('#disabledButton').popover('toggle');") 
    }) 
}) 

shinyApp(ui,server) 

enter image description here


如果你想這樣做沒有jQuery的,這將是一個解決方案:對我來說

library(shiny) 
library(shinyjs) 
library(shinyBS) 


ui <-shinyUI(fluidPage(useShinyjs(), 
         # checkbox for disabling and tooltip action 
         checkboxInput("disable", "Disable"), 

         # a button 
         actionButton("buttonId", "Some button"), 

         # uiOutput to realize logic for tooltip 
         uiOutput("trigger"))) 


server <- shinyServer(function(input,output, session){ 

    # on click of input$addPopover, trigger the popover over the disabled button 
    output$trigger <- renderUI({ 
    if(input$disable) { 
     shinyjs::disable("buttonId") 
     bsTooltip("buttonId", "This button is currently disabled.") 
    }else{ 
     shinyjs::enable("buttonId") 
     bsTooltip("buttonId", "") 
    } 
    }) 
}) 

shinyApp(ui,server) 

enter image description here

+0

這是一個很好的方式,謝謝。不幸的是,我在jQuery中什麼都不知道。你能給我提示我該如何做,所以當前被禁用的'actionButton'顯示懸停的彈出窗口?在我的應用程序中,我試圖做這樣的事情: 'if(condition == TRUE){shinyjs :: disable(buttonId); addTooltip(session,id ='buttonId',title = paste0('這個按鈕目前被禁用')',沒有很好的工作 –

+0

更新我的解決方案,包括「沒有jquery」 - 解決方案......奇怪的原因' addPopover'不起作用... – shosaco

+0

即使使用'bsTooltip'也不適用於我,即使在刪除ckeckbox後移動鼠標速度夠快,它也會顯示一個工具提示,但我沒有說我不喜歡jquery解決方案,它只是我需要彈出窗口顯示在'懸停'上,而不是按鈕單擊。但通常'懸停'不適用于禁用按鈕,這就是爲什麼我想'manial'選項 –