Reputation: 31
I am making a shiny app that finds the minimum or maximum of an equation. To maximise I simply want to use the negative of the equation and find its minimum. The function I'm using takes the input as a character. The as.character is giving me the following error: cannot coerce type 'closure' to vector of type 'character'.
UI:
library(shiny)
source("simulated_annealing.R")
ui <- fluidPage(
titlePanel("Simulated Annealing App"),
sidebarLayout(
position = "left",
sidebarPanel("User input",
textInput("ObjectiveFun",
h3("Objective Function"),
value = "(x+2*y-7)^2+(2*x+y-5)^2"),
radioButtons("maxormin",
h3("Goal"),
choices=c("Minimise"=1, "Maximise"=2)),),
mainPanel("System Outputs",
textOutput("finalvalues")),
),
)
SERVER:
server <- function(input, output)
{
output$finalvalues <- renderText({
Func <- as.character(reactive({input$ObjectiveFn}))
if(input$maxormin == 2)
{
Func <- paste(c("-(",Func,")"),sep="",collapse="",end="")
}
#the rest of the inputs to the function below seem to work so they are not included
value <- simannealing(Func,temp,I,A,alpha,nepochs,xlower,xupper,ylower,yupper)
finalvalues <- paste("Final value is:", value[3],"and x value: ", value[1], "and y value: ", value[2])
})
}
If I need to upload any of the other code please let me know
Upvotes: 0
Views: 41
Reputation: 10375
input$ObjectiveFn
is already reactive, so you don't need the reactive
around it.
Upvotes: 0