无法使用 Shinyjs() 禁用闪亮的应用程序单选按钮

2024-05-05

我正在尝试禁用闪亮的应用程序单选按钮(“趋势”)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)
     })

这是一个很老的问题,但我今天遇到了同样的问题并解决了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)")
    }
})

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 Shinyjs() 禁用闪亮的应用程序单选按钮 的相关文章

随机推荐