Currently trying to debug my Shiny app for a final class project in R. I keep receiving the "Error in as.vector: cannot coerce type 'closure' to vector of type 'character'" or another error to do with passing a double or string. Essentially, I want to have my user enter in the dimensions of the box and then have the application predict the Fed Ex charge and then the rate they should charge the consumer. My app's code layout is below:
ui <- fluidPage(
# Application title
titlePanel("Shipping Rate Estimator"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("method", label = "Shipping Method:",
choices = c("2 Day" = "2Day", "Express Saver" = "Express Saver", "First Overnight" = "First Overnight",
"Ground" = "Ground", "Priority Overnight" = "Priority Overnight", "Standard Overnight" = "Standard Overnight")),
numericInput("ht", label = ("Box Item Height:"), value = 0),
numericInput("wdth", label = ("Box Width:"), value = 0),
numericInput("lngth", label = ("Box Length:"), value = 0),
numericInput("lbs", label = ("Box Weight: "), value = 0),
textInput("destination","Destination Zipcode: ", value = '78212')
),
mainPanel(
textOutput("fed_ex_cost"),
textOutput("rate")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
df <- reactive({
shipMethod <- as.character(input$method)
# Add break if they enter something else
itemHt <- as.integer(input$ht)
itemWidth <- as.integer(input$wdth)
itemLength <- as.integer(input$lngth)
weight <- as.integer(input$lbs)
destination <- as.character(input$destination)
df <- rbind(df, data.frame(ship_via_fed_ex = c(shipMethod), stock_box_item_height = c(itemHt),
stock_box_item_width = c(itemWidth), stock_box_item_length = c(itemLength), actual_shipping_weight_fed_ex = c(weight),
ship_from_zip_code = c(destination)))
})
fed_ex_cost <- reactive({computation1(df)})
rate <- reactive({computation2(fed_ex_cost)})
output$fed_ex_cost <- renderText({
paste("Predicted Fed-Ex Shipping Cost: $", fed_ex_cost)
})
output$rate <-renderText({
paste("Appropriate Charge: $", rate)
})
}
# Run the application
shinyApp(ui = ui, server = server)
The computation1 calculates the predicted cost using our model's and one-hot encoding. Computation2 takes the charge * 1.20 for the rate. This is my first Shiny app so please excuse what's likely an easy error to fix. Additionally, please feel free to make any other suggestions on improving my code! Thank you!