«Ошибка на сервере: неиспользованные аргументы» - R блестящая ошибка приложения (функция сервера включает условные операторы) - PullRequest
1 голос
/ 17 марта 2020

Я новичок в R блестящий. Я пытался создать приложение, которое дает мне таблицу рангов на основе 4 параметров. Я успешно создал раздел пользовательского интерфейса (входная часть). Однако я не могу связать его с выходной таблицей должным образом. Как я упоминал ранее, я новичок в сиянии, я не могу понять ошибку. Когда я запускаю приложение, веб-приложение отображается в течение некоторого времени c, а затем исчезает, и сеансы R продолжают выполняться с предупреждением (ниже).

Warning: Error in server: unused arguments (input = list(<environment>, TRUE, function (x) 
x), output = list(<environment>, function (x) 
x))
  [No stack trace available]
Error in server(...) : 
  unused arguments (input = list(<environment>, TRUE, function (x) 
x), output = list(<environment>, function (x) 
x))

Мой код (Я проверил функцию "рангов", она отлично работает)

library(shiny)

rank_master = read.csv("master_rank.csv")

# Define UI for application that draws a histogram
ui <- fluidPage(
    titlePanel("Find the Best Supplier"),
    sidebarLayout(
        sidebarPanel(
            sliderInput("width", "Width", 28, 80, 40, post = " inches"),
            radioButtons("alloy", "Alloy Category: 0 = Low C & 1 = High C",
                         choices = c(0, 1), selected = 0),
            sliderInput("top", "Top X Suppliers",1,15,5, pre = "x = "),
            sliderInput("coil_ratio", "Exclusion", 0, 0.5, 0.1, 0.05)
        ),
        mainPanel("Best Suppliers for the Specified Parameters", 
                  dataTableOutput("results")
                  )

    )
)

# Define server logic required to draw a histogram
server <- function(width, alloy, top, coil_ratio){

    output$results = renderDataTable({

    new_table = subset(rank_master, ratio >= coil_ratio)   
    if (width >= 28 & width < 35 & alloy == 0){
        rank = as.data.frame(head(subset(new_table, width >= 28 & width < 35 & alloy_cat == 0, select = 
                                             c(supplier, mean_width_var, sd_width_var, rms, n_coils), top)))
        row.names(rank) = 1:nrow(rank)
        return(rank)
    } else if (width >= 28 & width < 35 & alloy == 1){
        rank1= as.data.frame(head(subset(new_table, width >= 28 & width < 35 & alloy_cat == 1, select =
                                             c(supplier, mean_width_var, sd_width_var, rms, n_coils)), top))
        row.names(rank1) = 1:nrow(rank1)
        return(rank1)
    } else if (width >= 35 & width < 50 & alloy == 0){
        rank2 = as.data.frame(head(subset(new_table, width >= 35 & width < 50 & alloy_cat == 0, select =
                                              c(supplier, mean_width_var, sd_width_var, rms, n_coils)), top))
        row.names(rank2) = 1:nrow(rank2)
        return(rank2)
    } else if (width >= 35 & width < 50 & alloy == 1){
        rank3 = as.data.frame(head(subset(new_table, width >= 35 & width < 50 & alloy_cat == 1, select = 
                                              c(supplier, mean_width_var, sd_width_var, rms, n_coils), top)))
        row.names(rank3) = 1:nrow(rank3)
        return(rank3)
    } else if (width >= 50 & width < 60 & alloy == 0){
        rank4 = as.data.frame(head(subset(new_table, width >= 50 & width < 60 & alloy_cat == 0, select =
                                              c(supplier, mean_width_var, sd_width_var, rms, n_coils)), top))
        row.names(rank4) = 1:nrow(rank4)
        return(rank4)
    } else if (width >= 50 & width < 60 & alloy == 1){
        rank5 = as.data.frame(head(subset(new_table, width >= 50 & width < 60 & alloy_cat == 1, select =
                                              c(supplier, mean_width_var, sd_width_var, rms, n_coils)), top))
        row.names(rank5) = 1:nrow(rank5)
        return(rank5)
    } else if (width >= 60 & width < 65 & alloy == 0){
        rank6 = as.data.frame(head(subset(new_table, width >= 60 & width < 65 & alloy_cat == 0, select =
                                              c(supplier, mean_width_var, sd_width_var, rms, n_coils)), top))
        row.names(rank6) = 1:nrow(rank6)
        return(rank6)
    } else if (width >= 60 & width < 65 & alloy == 1){
        rank7 = as.data.frame(head(subset(new_table, width >= 60 & width < 65 & alloy_cat == 1, select =
                                              c(supplier, mean_width_var, sd_width_var, rms, n_coils)), top))
        row.names(rank7) = 1:nrow(rank7)
        return(rank7)
    } else if (width >= 65 & width < 70 & alloy == 0){
        rank8 = as.data.frame(head(subset(new_table, width >= 65 & width < 70 & alloy_cat == 0, select =
                                              c(supplier, mean_width_var, sd_width_var, rms, n_coils)), top))
        row.names(rank8) = 1:nrow(rank8)
        return(rank8)
    } else if (width >= 65 & width < 70 & alloy == 1){
        rank9 = as.data.frame(head(subset(new_table, width >= 65 & width < 70 & alloy_cat == 1, select =
                                              c(supplier, mean_width_var, sd_width_var, rms, n_coils)), top))
        row.names(rank9) = 1:nrow(rank9)
        return(rank9)
    } else if (width >= 70 & width < 80 & alloy == 0){
        rank10 = as.data.frame(head(subset(new_table, width >= 70 & width < 80 & alloy_cat == 0, select =
                                               c(supplier, mean_width_var, sd_width_var, rms, n_coils)), top))
        row.names(rank10) = 1:nrow(rank10)
        return(rank10)
    } else if (width >= 70 & width < 80 & alloy == 1){
        rank11 = as.data.frame(head(subset(new_table, width >= 70 & width < 80 & alloy_cat == 1, select =
                                               c(supplier, mean_width_var, sd_width_var, rms, n_coils)), top))
        row.names(rank11) = 1:nrow(rank11)
        return(rank11)
    } else if(width < 28 | width > 80){
        "Please enter a width in the range of 28 to 80!"
    } else if(alloy != 0 | alloy != 1){
        "Incorrect Alloy Category! Please select 0 for Low Carbon Steel and 1 for High Carbon Steel"
    } else {
        "Incorrect parameters entered!"
    }
    })
}


shinyApp(ui, server)

Спасибо:)

1 Ответ

0 голосов
/ 17 марта 2020

Избегайте ввода дополнительных аргументов в функции сервера:

server <- function(width, alloy, top, coil_ratio){

Должно быть

server <- function(input, output) {

Затем вы можете использовать свои входные данные в своей выходной функции $ results. Например if(input$width >= 28

Я не знаю, что находится в master_rank.csv. Мы можем помочь вам лучше, если вы включите воспроизводимый пример { ссылка }

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...