The probability displayed after clicking the button should depend on the selected MODEL:
Display only MODEL1、 Display only MODEL2、Display MODEL1 + MODEL2。
for example:
when choose MODEL1、AGE:<18、SEX=1 ,the output is 0.15 and 0.25:
So,the output is:
Now,Display only MODEL1 and Display only MODEL2 is correct.
BBBBBUT!
Display MODEL1 + MODEL2 is incorrect.
Here is code:
data_1 <- data.frame(
MODEL=rep(c("MODEL1","MODEL1","MODEL1","MODEL1","MODEL2","MODEL2","MODEL2","MODEL2"),2),
DAY=rep(c(3,3,7,7),4),
AGE=rep(c("<18",">18"),8),
SEX=c(1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0),
AGE_PT=c(0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9)
)
ui <- fluidPage(
tabPanel("TEST FOR "),
# App title
titlePanel("TEST FOR Multiple selection?"),
# Sidebar layout
sidebarLayout(
sidebarPanel(
#年齡層下拉選擇按鈕
selectInput("AGE",label = h3("您的年齡是AGE?"),
choices = c("<18",">18"),
selected = "<18"),
# 性別圓形選擇按鈕
radioButtons(
inputId = "SEX",
label = "妳的性別SEX?",
choices = c("男性M" = 1, "女性W" = 0)
),
checkboxGroupButtons(
inputId = "MODEL",
label = "修改中的選取模型MODEL:",
choices = c("MODEL1","MODEL2"),
selected = "MODEL1",
checkIcon = list(
yes = icon("square-check"),
no = icon("square")
)
),
#可以點的按鈕,點下去才會計算
actionButton(
inputId = "calculate",
label = "計算機率calculate",
class = "btn-info"
)
),
# Web page functionality explanation
mainPanel(
verbatimTextOutput("results")
)
)
)
server <- function(input, output) {
dataInput <- reactive({
data_1 %>%
filter(AGE == input$AGE,
SEX == input$SEX,
MODEL == input$MODEL)
}) %>%
bindEvent(input$calculate)
output$results <- renderPrint({
res <- as.numeric(input$SEX)*0.5 + dataInput()$AGE_PT
paste("AGE+SEX:",res,"MODEL:" ,input$MODEL)
}) %>%
bindEvent(dataInput())
}
# Run the application
shinyApp(ui = ui, server = server)
thanks a lot!