r - 为什么 R while 循环不能用闪亮的框架实现?
问题描述
我正在尝试在闪亮的仪表板上创建一个简单的文本列表 UI。为此,我制作了一个 R 函数,它需要存储每个文本输入以存储在列表中。
readtasks <- function() {
df <- list()
while(TRUE) {
tasks <- readline(prompt="type your tasks: ")
# stop reading if no text was typed in
if (tasks == '')
break
# add the read data to the bottom of the list
df <- append(df,tasks)
}
print(df)
}
该功能适用于我的需求,但当涉及到闪亮时,它会显示很多错误。我急切地想知道,这个while循环如何有效地实现闪亮。我在谷歌和 StackOverflow 上搜索了很多关于这个的内容。如果可能的话,请给我一个例子。
谢谢
我尝试用上述功能制作一个闪亮的应用程序
ui<- fluidPage(
textInput(inputId = "text","add"),
actionButton("button",label = "enter"),
verbatimTextOutput("list")
)
server<- function(input,output,session){
df<- list()
while(TRUE) {
tasks <- input$text
# stop reading if no year was typed in
if (tasks == '')
break
# add the read data to the bottom of the dataframe
df <- append(df,tasks)
output$list<- renderprint({df})
}
}
shinyApp(ui = ui,server = server)
但它因以下错误而崩溃
Listening on http://127.0.0.1:7598
Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
61: stop
60: .getReactiveEnvironment()$currentContext
59: getCurrentContext
55: .subset2(x, "impl")$get
54: $.reactivevalues
52: server [#6]
Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
知道使用 while 循环执行函数真的很有帮助
再次感谢你
解决方案
推荐阅读
- python - pip 包在安装 aiohttp 时出错
- flutter - 我可以根据给定值的变化从代码中更改滑块点吗?
- python - 如何单击网格中的框并用颜色填充该框?
- sql-server - 组解决方案中的最大价值,也满足索引视图的要求
- python - 获取、存储和返回多个输入 Python
- box-api - 我如何在 Box 中签署文档,我对电子签名感兴趣?
- phpunit - 我得到了未定义的索引:livewire 测试中的指纹
- python - Python对熊猫数据框中列表中的元素进行排序
- c - 全局定义的变量作为函数返回
- javascript - Onclick 事件创建具有锁定大小的元素