如何获取单选按钮作为变量以应用条件?

时间:2019-02-08 17:37:44

标签: r shiny

我试图根据mt单选按钮的输入获取反应式表达式工作,我需要在单选按钮中获取一个级别作为变量,以便我可以对其进行应用(如果有条件的话)。但是我无法直接从input $ radio访问该级别以对其施加条件。

##Shiny web app
library(shiny)
ui<-fluidPage(
  #App Title
  titlePanel("Association Rule Mining"),

  #side bar layout with inp/op
  sidebarLayout(
    sidebarPanel(

      #slider input1
      sliderInput(inputId = "support",
                  label="Value of Support",
                  min=0.01,
                  max=1,
                  step = 0.01,
                  value = 0.01),
      #slider input 2
      sliderInput(inputId = "confidence",
                  label = "Value of confidence",
                  min=0.1,
                  max=1,
                  step=0.01,
                  value=0.5),
      radioButtons("radio","Rule Type",choices=c("All Rules","Large Income Rules","Small Income Rules"))

    ),
    #main panel for output
    mainPanel(
      verbatimTextOutput("Rules"),
      #plotOutput("plot_rules")
    )

  )
)



server<-function(input,output){
  a_rules<-reactive({
    if (input$radio==`All Rules`){
      rules<-apriori(adult_trans,parameter = list(support = input$support, confidence = input$confidence))  
    }
    else{
    type=switch(input$radio,
           `Large Income Rules` ="income=large",
           `Small Income Rules`="income=small")
           rules<-apriori(adult_trans,parameter = list(support = input$support, confidence = input$confidence),appearance = list(default="lhs",rhs=type))}


    subset_rules(rules)
    inspect(head(rules, 5))
      })

  #transrules<-reactive({apriori(adult_trans, parameter = list(support = input$support, confidence = input$confidence))})
  output$Rules<-renderPrint({a_rules()})
  #output$plot_rules<-renderPlot(plot(a_rules(),measure = c("support", "lift"), shading = "confidence"))
}
shinyApp(ui,server)

0 个答案:

没有答案