2017-01-27 202 views
1

我需要改變b閃爍的顏色的行動按鈕在R閃亮後點擊/按下。我可以更改懸停時的默認顏色和顏色,但在點擊後更改顏色方面存在問題。 當按鈕沒有點擊 - 藍色, 懸停 - 淺藍色, 點擊後 - 綠色。尋找解決這個問題的方法。改變bg顏色的行動按鈕後,點擊R閃亮

這裏是我的代碼 -

ui <- shinyUI(
dashboardPage (
dashboardHeader(), 
dashboardSidebar(), 
dashboardBody(
    tags$head(tags$style(HTML(" 
          .btn { 
          color:rgb(255,255,255); 
          text-align: left; 
          #border-color:rgb(0,144,197); 
          background-color:rgb(0,144,197);} 

          # #gobutton:active { 
          # background: green; 
          # } 

          .btn:hover{ 
             #border-color:rgb(232,245,251); 
          background-color: rgb(232,245,251);color: rgb(0,144,197);font-weight: bold; 
          } 
          "))), 



      actionButton("gobutton","Go"), 
      bsModal("formExample", "form", "gobutton", size = "small", # Enables Pop up Screen 

      # Different Shiny Widgets 

      textInput("first.name", "First Name", ""), 
      textInput("last.name", "Last Name",""), 
      dateInput('date',label = 'Date of Birth: yyyy-mm-dd',value = ""), 
      sliderInput("age", "Age in Yrs", 0, 100, 25, ticks = FALSE), 
      radioButtons("gender","Gender",choices = list("Male" = "Male", "Female" = "Female"),selected = "Male") 

    ) 
    ))) 

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

shinyApp(ui,server) 

回答

3

我能夠在你的CSS代碼添加一些CSS來做到這一點:

ui <- shinyUI(
    dashboardPage (
    dashboardHeader(), 
    dashboardSidebar(), 
    dashboardBody(
     tags$head(tags$style(HTML(" 
           .btn { 
           color:rgb(255,255,255); 
           text-align: left; 
           #border-color:rgb(0,144,197); 
           background-color:rgb(0,144,197);} 

           # #gobutton:active { 
           # background: green; 
           # } 

           .btn:hover{ 
           #border-color:rgb(232,245,251); 
           background-color: rgb(232,245,251);color: rgb(0,144,197);font-weight: bold; 
           } 
           .btn:focus{ 
           background-color:green; 
           } 

           "))), 



     actionButton("gobutton","Go"), 
     bsModal("formExample", "form", "gobutton", size = "small", # Enables Pop up Screen 

       # Different Shiny Widgets 

       textInput("first.name", "First Name", ""), 
       textInput("last.name", "Last Name",""), 
       dateInput('date',label = 'Date of Birth: yyyy-mm-dd',value = ""), 
       sliderInput("age", "Age in Yrs", 0, 100, 25, ticks = FALSE), 
       radioButtons("gender","Gender",choices = list("Male" = "Male", "Female" = "Female"),selected = "Male") 

    ) 
    ))) 

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

shinyApp(ui,server) 

上面似乎很好地工作:

enter image description here

我添加的CSS是:

.btn:focus{ 
    background-color:green; 
} 
+0

謝謝你的建議代碼。如果點擊儀表板中的任何地方,綠色將消失。在另外的需求中,如果有任何其他按鈕被點擊直到「Go」按鈕呈綠色,我需要激活藍色。儀表板有多個按鈕。 – string

2

您可以隨時使用shinyBS包。我可能會建議增加一個工具提示您的按鈕上懸停也

#rm(list = ls()) 
library(shiny) 
library(shinydashboard) 
library(shinyBS) 
ui <- dashboardPage(
    dashboardHeader(title = 'My Change Button Color'), 
    dashboardSidebar(sidebarMenu()), 
    dashboardBody(
    fluidRow(
     bsButton("button1", label = "Click Me", block = F, style="danger"), 
     bsTooltip(id = "button1", title = "Button 1 Explanation", placement = "right", trigger = "hover") 
    ) 
) 
) 

server <- (function(input, output, session) { 
    observeEvent(input$button1,{                                 
    updateButton(session, "button1",label = "Click Me", block = F, style = "success")                               
    })                                        
}) 

shinyApp(ui, server) 

enter image description here enter image description here

+0

感謝您的建議代碼。一個快速查詢可以自定義這些「bsButtons」的顏色,就像給出rgb代碼一樣。 – string

+0

這些顏色是在包中預先定義的,你有''(缺省,主要,成功,信息,警告或危險)'的'樣式''。欲瞭解更多信息,請訪問https://ebailey78.github.io/shinyBS/index.html –