3

我试图在input$Product !=A && input$month !="All"使用 Shinyjs 包时禁用闪亮的应用单选按钮(“趋势”),但没有成功。

我的ui页面定义为:

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)
     })
4

1 回答 1

4

这是一个很老的问题,但我今天遇到了同样的问题,并用shinyjsbasic解决了它jQuery。这是一个有点hacky的解决方案,但它对我有用:

您的解决方案可能如下所示:

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)")
    }
})

第一行禁用实际按钮,第二行禁用标签并赋予其“禁用外观”。

于 2016-10-26T10:31:52.810 回答