[英]R Shiny accessing a dynamic input
我剛接觸光澤,已經堅持了很長時間,到目前為止,我嘗試和閱讀的內容均未見成效。 我有一個下拉菜單,用戶可以在其中選擇一個問題,然后根據該問題在下拉菜單中填充響應號。 用戶選擇響應編號后,將繪制一個地圖。 我已經瀏覽了動態下拉列表,即已完成。 但是我無法訪問第二個用戶輸入的響應號,因此我可以相應地為地圖選擇數據。 我覺得這真的很簡單,我不知道為什么這行不通。 我收到此錯誤:
.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
...
})
}
))
包括輸入在內的反應性變量只能在使用以下方式之一創建的反應性范圍中訪問:
shiny::reactive
, shiny::eventReactive
shiny::reactive
shiny::observe
, shiny::observeEvent
shiny::observe
shiny::observeEvent
shiny::render*
或內部shiny::isolate
塊。
對於諸如日志記錄之類的操作,您可能希望observe
塊:
observe({print(choice_number())})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.