Right now I am using my own data, but the values are numeric...let's just pretend I am using the mtcars dataset that comes with R.
I would like to:
allow my user to select a numeric variable from a dataframe via a drop down menu
have the computer calculate the minimum and maximum values for said variable
allow my user to input a number between 1 and 50 from a slider input
Divide the difference between the maximum and minimum of the first variable by the value obtained from the slider input
The first error I got was:
- Non-numeric argument to binary operator
So I tried to coerce the variable using as.numeric(), but this led to my second error:
- NAs introduced by coercion
Putting a print(max(input$Var) line in my server.R file gives me the variable name instead of a number.
Any help with this would be greatly appreciated. I have posted part of my ui.r and server.r files below. Thank you in advance.
ui.R:
library(shiny)
load('mtcars')
shinyUI(pageWithSidebar(
headerPanel("MtCars Interactive Analysis Tool"),
sidebarPanel(
selectInput(inputId = "histVar",
label= "Pick Your Variable",
choices=names(mtcars),
selected = NULL)),
sliderInput(inputId = "binNum",
label = h5("Number of bins for Histogram--1 through 50 are allowed"),
min = 1,
max = 50,
value = 15,
step = 1)
mainpanel(...blah blah blah)
server.R:
library(shiny)
load("mtcars")
shinyServer(function(input, output) {
output$histPlot <- renderPlot({
varRangeGet <- range(input$histVar)
#print(varRangeGet)
#print(class(varRangeGet))
#print(max(input$histVar))
realRange<-(varRangeGet[[2]]- varRangeGet[[1]])
binwidthX <- realRange/input$binNum
# Errors out...can't continue
})
})
Again, thank you for any help on this...I don't understand why I can't perform simple calculations on an input variable within Shiny....