我是新手,我已经坚持了很长一段时间,而我迄今为止所尝试和阅读的东西都没有结果 . 我有一个下拉列表,用户将选择一个问题,然后根据问题,下拉列表将填充响应数字 . 在用户选择响应编号后,将绘制 Map . 我已经完成了动态下拉列表 . 但我无法访问第二个用户输入,即响应号,因此我可以相应地为 Map 选择我的数据 . 我觉得这很简单我不知道为什么这不起作用 . 我收到此错误:
.getReactiveEnvironment()中的错误$ currentContext():没有活动的响应上下文时不允许操作 . (你试图做一些只能在反应式表达式或观察者内部完成的事情 . )
我的代码如下,我暂时提出了特殊情况,后来我将扩展到列表的一般情况 .
library(shiny)
runApp(list(
ui = shinyUI(pageWithSidebar(
headerPanel('Dialect Comparison'),
sidebarPanel(
selectInput('Question', 'Choose The Question', c('100. Do you cut or mow the lawn or grass?'='Q100',
'101. Do you pass in homework or hand in homework?'='Q101')),
uiOutput('C')
),
mainPanel(
plotOutput('plot')
)
)
),
server = function(input, output){
output$C = renderUI({
ques = input$Question
selectInput('Choice', 'Choose The Response', seq(0,max(ling_data[,ques])))
})
##########
#The Data#
##########
#text = renderPrint({'uhu'})
#print(text()) #THIS WORKS
choice_number = renderPrint({input$Choice}) #http://shiny.rstudio.com/gallery/dynamic-ui.html
print(choice_number()) #it fails here
...
})
}
))
1 回答
只能在使用以下方法之一创建的反应范围中访问反应变量(包括输入):
shiny::reactive
,shiny::eventReactive
shiny::observe
,shiny::observeEvent
shiny::render*
或在
shiny::isolate
区块内 .对于像日志记录这样的操作,您可能需要
observe
block: