2017-12-09 12 views
2

로부터 액세스 입력 오브젝트이 위젯 값 input.num 통해 condition JS 발현 도달.반짝이 : 예 <code>numericInput("num", label = h3("Numeric input"), value = 1)</code> 위젯 갖는 경우 있도록 JS <code>input</code> 객체에 액세스 할 수있다, 인수 <code>condition</code> 반짝이 <code>conditionalPanel</code>에서 자신 JS 스크립트

동일한 방식으로 input 자체 JS 스크립트 (Shiny 앱에서 실행 됨) 또는 Shiny 앱 페이지에 열린 브라우저의 콘솔에서 액세스하는 방법에 대한 질문은 무엇입니까?

답변

2

아마도 가장 좋은 방법은 shiny:inputchanged events을 청취하는 것입니다.

library(shiny) 

shinyApp(
    ui = fluidPage(
    tags$head(tags$script(" 
     $(document).on('shiny:inputchanged', function(event) { 
     console.log(event); 
     console.log('[input] ' + event.name + ': ' + event.value); 
     }); 
    ")), 
    numericInput("num", "", 0, 0, 5), 
    textInput("txt", ""), 
    actionButton("action", "Action") 
), 
    server = function(input, output) {} 
) 

또한 백업 session$sendCustomMessageShiny.addCustomMessageHandler를 사용하여 서버에서 입력 값을 보낼 수 있습니다.


미등록 훨씬 적은 권장되는 방법 name:type 키 아래 Shiny.shinyapp.$inputValues 통해 직접 값을 저장하는 오브젝트를 상기 입력 값에 액세스 할 수있을 것이다 :

{ 
    "action:shiny.action": 4, 
    "num:shiny.number": 2, 
    "txt": "text" 
}