【问题标题】:how to save the entered text in a shiny app如何将输入的文本保存在闪亮的应用程序中
【发布时间】:2015-08-01 01:01:14
【问题描述】:

我想知道如何将用户输入的文本保存在闪亮的应用程序中,以便在服务器端使用它。 我想检查用户输入的值是否有效 在用户端有这个文本输入:

      textInput("entity1", "Enter a keyword")

在服务器端,我想使用以下代码检查用户的价值:

entity1 <- reactive({
if(input$actb >= 0 ){
  withProgress(session, min=1, max=15, expr={
    for(i in 1:15) {
      setProgress(message = 'please wait',detail = 'it may take some time',value=i)
      Sys.sleep(0.1)
    }
  })}
smallE= "[a-z]"
keyword = as.character(input$entity1)
if(match(input$entity1, smallE))
{
  message("sorry you did not enter a valid keyword. please try again")
  Sys.sleep(1)
}
else
  entity1 <- readTweets()

})

我尝试在服务器端声明一个全局变量来保存输入:

    if(match(as.vector(userInput), smallE))

userInput是一个全局变量,包含entity1的值

但是有一个错误提示:

as.vector(x, mode) 中的错误: 不能将“闭包”类型强制为“任何”类型的向量

有什么建议可以帮到我吗?

【问题讨论】:

    标签: r shiny shiny-server


    【解决方案1】:

    仅凭这段代码很难区分。我会避免调用任何全局变量,但是,在用户指定输入值之前,您可以分配 NULL 值。

    您还将对象和反应函数都称为“entity1”,所以这有点令人困惑。

    另一件事是您定义了对象“关键字”,但之后再也不会使用它。

    而且我认为使用 %in% 作为二进制文件而不是 match() 可能会更好。

    不确定这是否有帮助...但是您看到的错误专门针对代码的 as.vector() 部分。我什至不确定您为什么要使用它,因为 textInput 字段中的任何字符串都将作为向量出现。

    【讨论】:

      【解决方案2】:

      有一个验证函数,比如这个例子:

      validate(
        need(input$searchTerm != "", "Please, enter the correct search term")
      )
      

      【讨论】:

        猜你喜欢
        • 2015-01-17
        • 1970-01-01
        • 2013-01-26
        • 2014-04-11
        • 2021-10-25
        • 1970-01-01
        • 1970-01-01
        • 2021-05-25
        • 2016-11-01
        相关资源
        最近更新 更多