Shiny app error: Error in sample.int(length(x), size, replace, prob) : invalid 'size' argument
I am creating a Shiny app to predict positive flu cases for patients using a random forest model. The user can enter certain number of input variables through the app and woill be able to click on an actionButton and then see probability for positive flu. GeneXpert
(binary no) is the target variable for training RF model and all the other variables are numeric in nature. When I run the app I get an error.
Error in sample.int(length(x), size, replace, prob): invalid 'size' argument
Here is my code:
library(shiny)
library(randomForest, quietly=TRUE)
library(ggplot2)
ui <- fluidPage(
titlePanel("Random Forest Flu Prediction Model"),
sidebarLayout(
sidebarPanel(
numericInput("month",
label = "Enter the Month:",
min = 1, max = 12, value = 5, step = 1),
numericInput("DOI", label = "Enter the days of illness:",
min = 1, max = 7, value = 5, step = 1),
numericInput(inputId = "age", label = "Enter the age:",
min = 1, max = 120, value = 5, step = 1),
numericInput(inputId = "rhi", label = "cursympt_rhinorrhea:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "wt", label = "Enter your weight:",
min = 1, max = 400, value = 5, step = 0.5),
numericInput(inputId = "ht",
label = "Enter your Height:",
min = 1, max = 400, value = 1, step = 0.5),
numericInput(inputId = "sore", label = "cursympt_sorethroat.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "shkilchi", label =
"cursympt_shakingchills.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "shtbt", label = "cursympt_shortnessbreath.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "appt", label = "cursympt_appetite.factor:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "incsput", label = "cursympt_incrsputum.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "wheez", label = "cursympt_wheezing.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "stom", label = "cursympt_stomachpain.facto:",
min = 0, max = 1, value = 1, step = 1),
actionButton("Action", "Analyze")
),
mainPanel(
textOutput('dynamicText')
)
)
)
server <- function(input, output)
dataset =read.csv(file="Flu_Shiny_Data.csv",header=TRUE)
nobs <- nrow(dataset)
sample <- train <- sample(nrow(dataset), 0.8*nobs)
validate <- NULL
test <- setdiff(setdiff(seq_len(nrow(dataset)), train), validate)
input_features <- c("age","heightin","weightlb",
"cursympt_days","cursympt_incrsputum.factor",
"cursympt_sorethroat.factor","cursympt_rhinorrhea.factor",
"cursympt_shortnessbreath.factor","cursympt_wheezing.factor",
"cursympt_shakingchills.factor","cursympt_appetite.factor",
"cursympt_stomachpain.factor","Month")
input_numbers <- c("age","heightin","weightlb","cursympt_days",
"cursympt_incrsputum.factor","cursympt_sorethroat.factor",
"cursympt_rhinorrhea.factor", "cursympt_shortnessbreath.factor",
"cursympt_wheezing.factor","cursympt_shakingchills.factor",
"cursympt_appetite.factor","cursympt_stomachpain.factor","Month")
target_feature <- "GeneXpert"
result.rf <- randomForest::randomForest(as.factor(GeneXpert) ~ .,
data=dataset[sample,c(input_features, target_feature)],
ntree=500,
mtry=3,
importance=TRUE,
na.action=randomForest::na.roughfix,
replace=FALSE)
values <- reactiveValues()
observe(
if(input$Action>0)
newLine<-isolate(c(input$month,input$DOI,input$age,input$rhi,input$wt,
input$ht,input$sore,input$shkilchi,input$shtbt,
input$appt,input$incsput,input$wheez,input$stom))
isolate(values$dataset <- unlist(newLine))
)
output$dynamicText <- renderText(
if (is.null(values$dataset)))
return()
pr <- predict(result.rf, newdata=na.omit(values$dataset))
pr <- as.numeric(pr)
(pr-1)
)
# Run the application
shinyApp(ui = ui, server = server)
r shiny
add a comment |
I am creating a Shiny app to predict positive flu cases for patients using a random forest model. The user can enter certain number of input variables through the app and woill be able to click on an actionButton and then see probability for positive flu. GeneXpert
(binary no) is the target variable for training RF model and all the other variables are numeric in nature. When I run the app I get an error.
Error in sample.int(length(x), size, replace, prob): invalid 'size' argument
Here is my code:
library(shiny)
library(randomForest, quietly=TRUE)
library(ggplot2)
ui <- fluidPage(
titlePanel("Random Forest Flu Prediction Model"),
sidebarLayout(
sidebarPanel(
numericInput("month",
label = "Enter the Month:",
min = 1, max = 12, value = 5, step = 1),
numericInput("DOI", label = "Enter the days of illness:",
min = 1, max = 7, value = 5, step = 1),
numericInput(inputId = "age", label = "Enter the age:",
min = 1, max = 120, value = 5, step = 1),
numericInput(inputId = "rhi", label = "cursympt_rhinorrhea:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "wt", label = "Enter your weight:",
min = 1, max = 400, value = 5, step = 0.5),
numericInput(inputId = "ht",
label = "Enter your Height:",
min = 1, max = 400, value = 1, step = 0.5),
numericInput(inputId = "sore", label = "cursympt_sorethroat.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "shkilchi", label =
"cursympt_shakingchills.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "shtbt", label = "cursympt_shortnessbreath.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "appt", label = "cursympt_appetite.factor:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "incsput", label = "cursympt_incrsputum.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "wheez", label = "cursympt_wheezing.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "stom", label = "cursympt_stomachpain.facto:",
min = 0, max = 1, value = 1, step = 1),
actionButton("Action", "Analyze")
),
mainPanel(
textOutput('dynamicText')
)
)
)
server <- function(input, output)
dataset =read.csv(file="Flu_Shiny_Data.csv",header=TRUE)
nobs <- nrow(dataset)
sample <- train <- sample(nrow(dataset), 0.8*nobs)
validate <- NULL
test <- setdiff(setdiff(seq_len(nrow(dataset)), train), validate)
input_features <- c("age","heightin","weightlb",
"cursympt_days","cursympt_incrsputum.factor",
"cursympt_sorethroat.factor","cursympt_rhinorrhea.factor",
"cursympt_shortnessbreath.factor","cursympt_wheezing.factor",
"cursympt_shakingchills.factor","cursympt_appetite.factor",
"cursympt_stomachpain.factor","Month")
input_numbers <- c("age","heightin","weightlb","cursympt_days",
"cursympt_incrsputum.factor","cursympt_sorethroat.factor",
"cursympt_rhinorrhea.factor", "cursympt_shortnessbreath.factor",
"cursympt_wheezing.factor","cursympt_shakingchills.factor",
"cursympt_appetite.factor","cursympt_stomachpain.factor","Month")
target_feature <- "GeneXpert"
result.rf <- randomForest::randomForest(as.factor(GeneXpert) ~ .,
data=dataset[sample,c(input_features, target_feature)],
ntree=500,
mtry=3,
importance=TRUE,
na.action=randomForest::na.roughfix,
replace=FALSE)
values <- reactiveValues()
observe(
if(input$Action>0)
newLine<-isolate(c(input$month,input$DOI,input$age,input$rhi,input$wt,
input$ht,input$sore,input$shkilchi,input$shtbt,
input$appt,input$incsput,input$wheez,input$stom))
isolate(values$dataset <- unlist(newLine))
)
output$dynamicText <- renderText(
if (is.null(values$dataset)))
return()
pr <- predict(result.rf, newdata=na.omit(values$dataset))
pr <- as.numeric(pr)
(pr-1)
)
# Run the application
shinyApp(ui = ui, server = server)
r shiny
add a comment |
I am creating a Shiny app to predict positive flu cases for patients using a random forest model. The user can enter certain number of input variables through the app and woill be able to click on an actionButton and then see probability for positive flu. GeneXpert
(binary no) is the target variable for training RF model and all the other variables are numeric in nature. When I run the app I get an error.
Error in sample.int(length(x), size, replace, prob): invalid 'size' argument
Here is my code:
library(shiny)
library(randomForest, quietly=TRUE)
library(ggplot2)
ui <- fluidPage(
titlePanel("Random Forest Flu Prediction Model"),
sidebarLayout(
sidebarPanel(
numericInput("month",
label = "Enter the Month:",
min = 1, max = 12, value = 5, step = 1),
numericInput("DOI", label = "Enter the days of illness:",
min = 1, max = 7, value = 5, step = 1),
numericInput(inputId = "age", label = "Enter the age:",
min = 1, max = 120, value = 5, step = 1),
numericInput(inputId = "rhi", label = "cursympt_rhinorrhea:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "wt", label = "Enter your weight:",
min = 1, max = 400, value = 5, step = 0.5),
numericInput(inputId = "ht",
label = "Enter your Height:",
min = 1, max = 400, value = 1, step = 0.5),
numericInput(inputId = "sore", label = "cursympt_sorethroat.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "shkilchi", label =
"cursympt_shakingchills.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "shtbt", label = "cursympt_shortnessbreath.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "appt", label = "cursympt_appetite.factor:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "incsput", label = "cursympt_incrsputum.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "wheez", label = "cursympt_wheezing.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "stom", label = "cursympt_stomachpain.facto:",
min = 0, max = 1, value = 1, step = 1),
actionButton("Action", "Analyze")
),
mainPanel(
textOutput('dynamicText')
)
)
)
server <- function(input, output)
dataset =read.csv(file="Flu_Shiny_Data.csv",header=TRUE)
nobs <- nrow(dataset)
sample <- train <- sample(nrow(dataset), 0.8*nobs)
validate <- NULL
test <- setdiff(setdiff(seq_len(nrow(dataset)), train), validate)
input_features <- c("age","heightin","weightlb",
"cursympt_days","cursympt_incrsputum.factor",
"cursympt_sorethroat.factor","cursympt_rhinorrhea.factor",
"cursympt_shortnessbreath.factor","cursympt_wheezing.factor",
"cursympt_shakingchills.factor","cursympt_appetite.factor",
"cursympt_stomachpain.factor","Month")
input_numbers <- c("age","heightin","weightlb","cursympt_days",
"cursympt_incrsputum.factor","cursympt_sorethroat.factor",
"cursympt_rhinorrhea.factor", "cursympt_shortnessbreath.factor",
"cursympt_wheezing.factor","cursympt_shakingchills.factor",
"cursympt_appetite.factor","cursympt_stomachpain.factor","Month")
target_feature <- "GeneXpert"
result.rf <- randomForest::randomForest(as.factor(GeneXpert) ~ .,
data=dataset[sample,c(input_features, target_feature)],
ntree=500,
mtry=3,
importance=TRUE,
na.action=randomForest::na.roughfix,
replace=FALSE)
values <- reactiveValues()
observe(
if(input$Action>0)
newLine<-isolate(c(input$month,input$DOI,input$age,input$rhi,input$wt,
input$ht,input$sore,input$shkilchi,input$shtbt,
input$appt,input$incsput,input$wheez,input$stom))
isolate(values$dataset <- unlist(newLine))
)
output$dynamicText <- renderText(
if (is.null(values$dataset)))
return()
pr <- predict(result.rf, newdata=na.omit(values$dataset))
pr <- as.numeric(pr)
(pr-1)
)
# Run the application
shinyApp(ui = ui, server = server)
r shiny
I am creating a Shiny app to predict positive flu cases for patients using a random forest model. The user can enter certain number of input variables through the app and woill be able to click on an actionButton and then see probability for positive flu. GeneXpert
(binary no) is the target variable for training RF model and all the other variables are numeric in nature. When I run the app I get an error.
Error in sample.int(length(x), size, replace, prob): invalid 'size' argument
Here is my code:
library(shiny)
library(randomForest, quietly=TRUE)
library(ggplot2)
ui <- fluidPage(
titlePanel("Random Forest Flu Prediction Model"),
sidebarLayout(
sidebarPanel(
numericInput("month",
label = "Enter the Month:",
min = 1, max = 12, value = 5, step = 1),
numericInput("DOI", label = "Enter the days of illness:",
min = 1, max = 7, value = 5, step = 1),
numericInput(inputId = "age", label = "Enter the age:",
min = 1, max = 120, value = 5, step = 1),
numericInput(inputId = "rhi", label = "cursympt_rhinorrhea:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "wt", label = "Enter your weight:",
min = 1, max = 400, value = 5, step = 0.5),
numericInput(inputId = "ht",
label = "Enter your Height:",
min = 1, max = 400, value = 1, step = 0.5),
numericInput(inputId = "sore", label = "cursympt_sorethroat.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "shkilchi", label =
"cursympt_shakingchills.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "shtbt", label = "cursympt_shortnessbreath.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "appt", label = "cursympt_appetite.factor:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "incsput", label = "cursympt_incrsputum.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "wheez", label = "cursympt_wheezing.facto:",
min = 0, max = 1, value = 1, step = 1),
numericInput(inputId = "stom", label = "cursympt_stomachpain.facto:",
min = 0, max = 1, value = 1, step = 1),
actionButton("Action", "Analyze")
),
mainPanel(
textOutput('dynamicText')
)
)
)
server <- function(input, output)
dataset =read.csv(file="Flu_Shiny_Data.csv",header=TRUE)
nobs <- nrow(dataset)
sample <- train <- sample(nrow(dataset), 0.8*nobs)
validate <- NULL
test <- setdiff(setdiff(seq_len(nrow(dataset)), train), validate)
input_features <- c("age","heightin","weightlb",
"cursympt_days","cursympt_incrsputum.factor",
"cursympt_sorethroat.factor","cursympt_rhinorrhea.factor",
"cursympt_shortnessbreath.factor","cursympt_wheezing.factor",
"cursympt_shakingchills.factor","cursympt_appetite.factor",
"cursympt_stomachpain.factor","Month")
input_numbers <- c("age","heightin","weightlb","cursympt_days",
"cursympt_incrsputum.factor","cursympt_sorethroat.factor",
"cursympt_rhinorrhea.factor", "cursympt_shortnessbreath.factor",
"cursympt_wheezing.factor","cursympt_shakingchills.factor",
"cursympt_appetite.factor","cursympt_stomachpain.factor","Month")
target_feature <- "GeneXpert"
result.rf <- randomForest::randomForest(as.factor(GeneXpert) ~ .,
data=dataset[sample,c(input_features, target_feature)],
ntree=500,
mtry=3,
importance=TRUE,
na.action=randomForest::na.roughfix,
replace=FALSE)
values <- reactiveValues()
observe(
if(input$Action>0)
newLine<-isolate(c(input$month,input$DOI,input$age,input$rhi,input$wt,
input$ht,input$sore,input$shkilchi,input$shtbt,
input$appt,input$incsput,input$wheez,input$stom))
isolate(values$dataset <- unlist(newLine))
)
output$dynamicText <- renderText(
if (is.null(values$dataset)))
return()
pr <- predict(result.rf, newdata=na.omit(values$dataset))
pr <- as.numeric(pr)
(pr-1)
)
# Run the application
shinyApp(ui = ui, server = server)
r shiny
r shiny
edited Nov 16 '18 at 5:19
Vishesh Shrivastav
1,2362824
1,2362824
asked Nov 16 '18 at 3:01
Avichandra singhAvichandra singh
13
13
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330813%2fshiny-app-error-error-in-sample-intlengthx-size-replace-prob-invalid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330813%2fshiny-app-error-error-in-sample-intlengthx-size-replace-prob-invalid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown