[英]r Using action buttons to hide/show checkboxes
Say I had the following code... 说我有以下代码...
ui.r 用户界面
library(shiny)
ui <- fluidPage(
actionButton("fishButton", label = "Fish"),
checkboxGroupInput("Check1",label=h4 ("Fish:"), choices = c("Bass","Shark","Tuna")),
actionButton("reptileButton", label = "Reptile"),
checkboxGroupInput("Check2",label=h4 ("Reptile:"), choices = c("Komodo","Skink","Snake")),
actionButton("mammalButton", label = "Mammal"),
checkboxGroupInput("Check3",label=h4 ("Mammals:"), choices = c("Dog","Cat","Bear")),
actionButton("birdButton", label = "Bird"),
checkboxGroupInput("Check4",label=h4 ("Birds:"), choices = c("Budgie","Parrot","Cockatiel")),
actionButton("amphibianButton", label = "Amphibian"),
checkboxGroupInput("Check5",label=h4 ("Amphibian:"), choices = c("Frog","Toad","Salamander"))
)
Is there a way to use conditional panels to hide/show the checkboxGroups by clicking on the appropriate actionButton? 有没有一种方法可以通过单击适当的actionButton来使用条件面板来隐藏/显示checkboxGroups? As I understand it the actionButton only stores an integer that starts at 0 and increases by 1 with each click of the button, which doesn´t seem very helpful in this case.
据我了解,actionButton仅存储一个整数,该整数从0开始,每次单击该按钮时增加1,这在这种情况下似乎没有太大帮助。 Would it be possible to have a conditional panel that only showed itself when it´s actionButton value was an even number or somesuch?
是否可以有一个仅在其actionButton值为偶数或类似数值时才显示自己的条件面板?
You can do using shinyJS package: 您可以使用ShinyJS包:
install.packages("shinyjs")
In the ui, init the field as hidden and call the toggle on the button click 在ui中,将字段初始化为隐藏状态,然后在按钮上调用切换按钮,然后点击
ui.R : ui.R :
library(shiny)
library(shinyjs)
shinyUI(fluidPage(
shinyjs::useShinyjs(),
actionButton("fishButton", label = "Fish"),
hidden(
checkboxGroupInput("Check1",label=h4 ("Fish:"), choices = c("Bass","Shark","Tuna"))
)
))
server.R 服务器
library(shiny)
library(shinyjs)
shinyServer(function(input, output) {
observeEvent(input$fishButton, {
toggle("Check1")
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.