2015-09-24 156 views
0

我是新來的閃亮,我一直堅持這一段時間,迄今爲止我嘗試和閱讀的東西沒有成果。我有一個下拉菜單,用戶將選擇一個問題,然後根據問題,下拉列表中將填入響應號碼。用戶選擇響應編號後,將繪製一張地圖。我已經通過了動態下拉列表,完成了。但我無法訪問第二個用戶輸入,即響應編號,因此我可以相應地爲地圖選擇我的數據。我覺得這很簡單,我不知道爲什麼這不起作用。我收到此錯誤:R閃亮訪問動態輸入

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.)

我的代碼如下,我試探性地提出在特殊情況下,我稍後會展開以列出了一般情況。

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

'{觀察(打印(choice_number())})' – zero323

+0

謝謝!這看起來很有希望,如果你讓這個答案我可以解決這個問題。 – plumSemPy

回答

1

反應變量,包括輸入端,可以僅在反應性範圍使用以下之一創建訪問:

  • shiny::reactiveshiny::eventReactive
  • shiny::observeshiny::observeEvent
  • shiny::render*

shiny::isolate區塊內。

對於像伐木行動你可能想observe塊:

observe({print(choice_number())})