R 在Shining中绘制动态C5.0决策树
我正在开发一个闪亮的应用程序,让用户根据需要选择因变量/自变量,然后执行C5.0生成摘要和树形图。但是,生成绘图时出现错误消息。有人知道解决办法吗?请查找代码:R 在Shining中绘制动态C5.0决策树,r,shiny,R,Shiny,我正在开发一个闪亮的应用程序,让用户根据需要选择因变量/自变量,然后执行C5.0生成摘要和树形图。但是,生成绘图时出现错误消息。有人知道解决办法吗?请查找代码: library(shiny) ui <- fluidPage( titlePanel('Plotting Decision Tree'), sidebarLayout( sidebarPanel( h3('iris data'), uiOutput('choose_y'), u
library(shiny)
ui <- fluidPage(
titlePanel('Plotting Decision Tree'),
sidebarLayout(
sidebarPanel(
h3('iris data'),
uiOutput('choose_y'),
uiOutput('choose_x'),
actionButton('c50', label = 'Generate C5.0 summary and plot')
),
mainPanel(
verbatimTextOutput('tree_summary'),
plotOutput('tree_plot_c50')
)
)
)
# server.R
library(shiny)
library(C50)
server <- function(input, output) {
output$choose_y <- renderUI({
is_factor <- sapply(iris, FUN = is.factor)
y_choices <- names(iris)[is_factor]
selectInput('choose_y', label = 'Choose Target Variable', choices = y_choices)
})
output$choose_x <- renderUI({
x_choices <- names(iris)[!names(iris) %in% input$choose_y]
checkboxGroupInput('choose_x', label = 'Choose Predictors', choices = x_choices)
})
observeEvent(input$c50, {
c50_fit <- C5.0(as.formula(paste(isolate(input$choose_y), '~', paste(isolate(input$choose_x), collapse = '+'))), data = iris)
output$tree_summary <- renderPrint(summary(c50_fit))
output$tree_plot_c50 <- renderPlot({
plot(c50_fit)
})
})
}
shinyApp(ui, server)
库(闪亮)
在服务器中的ui。R
尝试
function(input, output) {
output$choose_y <- renderUI({
is_factor <- sapply(iris, FUN = is.factor)
y_choices <- names(iris)[is_factor]
selectInput('choose_y', label = 'Choose Target Variable', choices = y_choices)
})
output$choose_x <- renderUI({
x_choices <- names(iris)[!names(iris) %in% input$choose_y]
checkboxGroupInput('choose_x', label = 'Choose Predictors', choices = x_choices)
})
observeEvent(input$c50, {
form <- paste(isolate(input$choose_y), '~', paste(isolate(input$choose_x), collapse = '+'))
c50_fit <- eval(parse(text = sprintf("C5.0(%s, data = iris)", form)))
output$tree_summary <- renderPrint(summary(c50_fit))
output$tree_plot_c50 <- renderPlot({
plot(c50_fit)
})
})
}
功能(输入、输出){
输出$choose______________________________________________________________!