gpt4 book ai didi

r - 无法使用 Shinyjs() 禁用 Shiny 的应用程序单选按钮

转载 作者:行者123 更新时间:2023-12-04 02:15:08 25 4
gpt4 key购买 nike

input$Product !=A && input$month !="All" 使用 Shinyjs 包时,我试图禁用 Shiny 的应用程序单选按钮(“趋势”),但一直不成功。

我的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 解决了它。这是一个有点 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)")
}
})

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

关于r - 无法使用 Shinyjs() 禁用 Shiny 的应用程序单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34733147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com