Невозможно отключить блестящую радиокнопку приложения с помощью Shinyjs ()

Я пытаюсь отключить блестящую радиокнопку приложения («Тренд»), когда input$Product !=A && input$month !="All" использую пакет Shinyjs, но безуспешно.

Моя страница пользовательского интерфейса определяется как:

ui <- fluidPage(
   shinyjs::useShinyjs(),
   pageWithSidebar(
   titlePanel("Analytics"),

    sidebarPanel(
      selectInput("product",
              label = "Choose a Product",
              choices = list("A", "B", "C", "All")),

      selectInput("month",
              label = "Choose TimeFrame",
              choices = list("June", "July", "August", "September", "All")),

      radioButtons('ptype', label ="Plot Type",
                c(Histogram = 'histogram',
                  Box = 'boxp',
                  Trend = 'trendp')
               )

),

Мой код на стороне сервера:

 shinyServer(function (input, output, session) {

  mydata<- read.csv("mydataQ1fy16.csv")

  observe({shinyjs::toggleState("trendp", input$product != "A" && input$month != "All") })    

    getMonthproduct <- reactive( {
      if(input$month != "All" &input$product !="All") {
         plotdata <- mydata %>% filter(Product ==input$product, Monthly ==input$month)} 

       else if (input$month =="All" & input$product =="All") {
         plotdata <- mydata
          }
         else if(input$product == "All") {
           plotdata <- mydata %>% filter(Monthly == input$month)

         }
          else if(input$month == "All") {
            plotdata <- mydata %>% filter(Product == input$product)

           }
     return(plotdata)
     })

person sgknr    schedule 11.01.2016    source источник
comment
Я автор shinyjs. Вы не можете отключить конкретную радиокнопку, вы можете отключить только всю группу радиокнопок вместе.   -  person DeanAttali    schedule 12.01.2016
comment
Спасибо за ответ.   -  person sgknr    schedule 12.01.2016


Ответы (1)


Это довольно старая проблема, но сегодня я столкнулся с той же проблемой и решил ее с помощью shinyjs и базового jQuery. Это немного хакерское решение, но оно работает для меня:

Ваше решение может выглядеть так:

observe({
    if (input$product != "A" && input$month !="All") {
        shinyjs::disable(selector = "[type=radio][value=trendp]")
        shinyjs::runjs("$('[type=radio][value=trendp]').parent().parent().addClass('disabled').css('opacity', 0.4)")
    }
})

Первая строка отключает настоящую кнопку, а вторая отключает метку и придает ей «отключенный вид».

person user1991825    schedule 26.10.2016