Мы можем добавить два buttons
(как указано в вопросе) в коде UI
следующим образом:
actionButton("output", "Output"), # Button to get Output
actionButton("accuracy", "Accuracy") # Button to get accuracy
Теперь мы можем наблюдать событие нажатия кнопки следующим образом (без данных IЯ не уверен, работает ли следующий код или нет):
observeEvent(input$output, {
print(final1) # Print the outvalues here as button Output is clicked
})
observeEvent(input$accuracy, {
print(caret::confusionMatrix(cm2)) # Print confusion matrix here as button accuracy is clicked
})
Обновлен код:
runApp(
list(
ui = fluidPage(
titlePanel("Upload & Results"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose Excel File',accept = c(".xlsx")),
actionButton("output", "Output"), # Button to get Output
actionButton("accuracy", "Accuracy") # Button to get accuracy
),
mainPanel(
fixedRow(
column(10,DT::dataTableOutput("contents"))
)
)
)
),
server = function(input, output){
output$contents <- renderDataTable({
req(input$file1)
inFile <- input$file1
df_test=read_excel(inFile$datapath, 1)
df1_test = subset(df_test, select=c("Number" ,
"Category" ,"Country" ,
"State" , "Region","PkValue" ,"ASTvalue" ,"DMValue" ,"Geo","Demo"))
Probabilty_Score = predict(classifier, type = 'response',newdata = df1_test)
Output = as.factor(ifelse(Probabilty_Score<0.55,0,1))
cm2 = table(df_test$Result, Output)
final=df_test[,c("Number","Result")]
final1=cbind(final,Output,Probabilty_Score)
observeEvent(input$output, {
print(final1) # Print the outvalues here as button Output is clicked
})
observeEvent(input$accuracy, {
print(caret::confusionMatrix(cm2)) # Print confusion matrix here as button accuracy is clicked
})
# In the following line, return data.frame that you would like to see
return(DT::datatable(iris, options = list(pageLength = 10)))
})
}
)
)