ewall(parse(text ="f")))在Shinypass.io上 [英] eval(parse(text="f")) on shinypass.io
问题描述
我想编写一个应用程序,使用户可以使用textInput输入功能,然后对该功能执行某些操作.这是一个玩具示例:
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()
})
})
))
,这在我的本地计算机上运行时效果很好.但是,当我将其提交给shinyapps.io时,出现错误:找不到对象x.似乎eval的envir参数存在问题,但我无法找出它是什么.
and this works just fine when run on my computer locally. But when i submit it to shinyapps.io i get the error: object x not found. It seems there is a problem with the envir argument of eval, but i have not been able to find out what it is.
当然,一般来说,关于eval(parse())构造有很多讨论,因此,如果有人对如何执行此操作有建议(具有在框中键入表达式并将其翻转的功能)进入一个函数),我也将不胜感激.
There is of course a lot of discussion on the eval(parse()) construct in general, so if anyone has a suggestion on how to do this (have the ability to type in an expression in a box and get it turned into a function) differently i would also be grateful.
狼帮
推荐答案
尝试了许多事情之后,我终于使这一工作了:
After trying a number of things i finally got this one to work:
代替
f <- function(x) eval(parse(text = input$fun), envir = list(x))
使用
eval(parse(text = paste("f <- function(x)",input$fun,sep="")))
我不知道为什么两者都可以在本地计算机上运行,但是只有第二个可以在Shinyapps.io上运行.另外,如果有人有其他方法可以做到这一点,我仍然会很感兴趣.
i have no idea why both work on my computer locally but only the second works on shinyapps.io . Also, i would still be interested if anyone has a different way to do this.
狼帮
这篇关于ewall(parse(text ="f")))在Shinypass.io上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!