我试图在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')
)
),
Run Code Online (Sandbox Code Playgroud)
我的服务器端代码:
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)
})
Run Code Online (Sandbox Code Playgroud)
这是一个相当老的问题,但我今天遇到了同样的问题并用shinyjsbasic解决了它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)")
}
})
Run Code Online (Sandbox Code Playgroud)
第一行禁用实际按钮,第二行禁用标签并赋予其“禁用外观”。
| 归档时间: |
|
| 查看次数: |
1550 次 |
| 最近记录: |