eval(parse(text=“f”)) on shinypass.io
问题 I want to write an app that lets the user enter a function using textInput, and then does something with the function. Here is a toy example: shinyUI(fluidPage( titlePanel("Test"), sidebarLayout( sidebarPanel( textInput("fun","function:",value="x") ), mainPanel( uiOutput("text") ) ) shinyServer(function(input, output) { findMax <- reactive({ f <- function(x) eval(parse(text = input$fun), envir = list(x)) x < seq(0,1,length=100) max(f(x)) }) output$text <- renderText( { findMax() }) }) )) and