单击R(闪亮)中的重置按钮取消选中单选按钮

时间:2016-12-19 12:50:31

标签: r shiny

我试图在点击Rest按钮时取消选中单选按钮。 我正在使用Shiny包来生成这些单选按钮。 单击单选按钮"比较",使用多个复选框调用ConditionalPanel。 选择任意数量的Checkbox&单击比较按钮进行比较。 我想在单击“重置”按钮时折叠ConditionalPanel。 或取消选中Radion按钮,使其自动隐藏ConditionalPanel。

ui.R

sidebarLayout( 
sidebarPanel( 
selectInput("villNane", "Choose a Village:", choices = c("All","Village1", "Village2","Village3","Village4","Village5"), selected = "All"), 
selectInput("YesNo", "Vaccinated / Not Vaccinated:", choices = c("Yes","No")), 
radioButtons("compare", "Comparison :", choices="Compare", selected = character(0), inline = FALSE,width = NULL),      
  conditionalPanel(
    condition="input.compare =='Compare'",
    checkboxGroupInput(inputId="somevalue", label="Village :",choices=c("Village1","Village2","Village3","Village4","Village5"), selected=NULL, inline=TRUE),
    actionButton("compAction", "Compare"),
    actionButton("resetAction", "Reset")
  )

server.R

if(inAc == 1){
        CB <-input$somevalue
        if((YN == 'Yes') &(villName=="All")){
          layout(matrix(c(1,2,3,4,5), 2,2, byrow = TRUE),widths=c(3,3), heights=c(3,3))
          for (val in 1:length(CB)) {
            gotData1 <- get(CB[val],vac)
            pct <- round(gotData1/sum(gotData1)*100)
            lbls <- c("Attack", "Not Attack")
            lbls2 <- paste(lbls, "-", pct, "%")
            pie(gotData1,labels=lbls2,radius=1.15)
          }
        }

      }

1 个答案:

答案 0 :(得分:1)

我认为您可能会更容易使用shinyjs包。

library(shiny)
library(shinyjs)

shinyApp(
  ui = 
    shinyUI(
      sidebarLayout( 
        sidebarPanel(
          useShinyjs(),
          verbatimTextOutput("display"),
          selectInput("villNane", "Choose a Village:", choices = c("All","Village1", "Village2","Village3","Village4","Village5"), selected = "All"), 
          selectInput("YesNo", "Vaccinated / Not Vaccinated:", choices = c("Yes","No")), 
          actionButton("compare", "Compare"),
          hidden(
            checkboxGroupInput(inputId="somevalue", label="Village :",choices=c("Village1","Village2","Village3","Village4","Village5"), selected=NULL, inline=TRUE)
          ),

          actionButton("compAction", "Compare"),
          actionButton("resetAction", "Reset")
        ),
        mainPanel()
      )
    ),

  server = 
    shinyServer(function(input, output, session){
      observeEvent(
        input$compare,
        {
           show("somevalue")
        }
      )

      observeEvent(
        input$resetAction,
        {
          hide("somevalue")
        }
      )

    })
)