2016-10-01 2 views
0

사용자가 데이터를 입력 한 다음 반짝이는 서버가 일부 결과를 계산할 수있게하는 응용 프로그램을 만들려고합니다. 예를 들어 반짝이는 플롯 또는 데이터 테이블을 생성 할 수 있습니다.Q : 반짝이는 앱 출력 결과를 새 페이지로 만드는 방법은 무엇입니까?

그러나 UI의 공간으로 인해 공간이 부족합니다. 입력란과 앱의 문서가 전체 화면으로 표시됩니다. 반짝이는 결과가 화면의 맨 아래에 표시됩니다.

결과를 보여주기 위해 반짝이는 팝업 메시지 상자를 만들 수있는 방법이 있습니까?

내 sudo는 코드는 다음과 같습니다

ui <- fluidPage(
    textInput("text", "Name"), 
    numericInput("age", "Age", 20), 
    actionButton("demo", "Fill in fields with demo")) 
server <- function(input, output, session) { 
    observeEvent(input$demo, { 

      **************************** 
      OpenNewPage/MoveScreenDown() 
      **************************** 

      updateTextInput(session, "text", value = H) 
      updateNumericInput(session, "age", value = "30") 
    })} 

클릭하면 메시지 상자 팝업을 "데모"또는 나는 결과 부분에 화면 이동을하고 텍스트의 상단에있을 수 있습니다 화면.

답변

0

결과를 별도의 창에 표시하는 옵션이 있습니다. 그러나 같은 창에서 모든 것을 갖는 것이 더 쉬울 수도 있습니다.

shinyBS 라이브러리를 사용하여 플롯을 표시하는 모달 창을 만들 수 있습니다. 또 다른 옵션은 JavaScript를 사용하여 스크롤을 페이지의 맨 아래로 이동하는 것입니다. 다음 예제에 두 가지 옵션을 추가 했으므로 어떤 옵션이 더 적합한 지 확인할 수 있습니다.

library(shiny) 
library(shinyBS) 
runApp(list(
    ui = shinyUI(fluidPage(
    textInput("text", "Name"), 
    numericInput("age", "Age", 20), 
    # option 1, using ShinyBS with a modal window 
    actionButton("demo", "Using a modal"), 
    # modal window to show the plot 
    bsModal("largeModalID","Results", "demo", size = "large", plotOutput('plot')),  
    # Option 2, action button with a JavaScript function to move the scroll to the bottom 
    # after drawing the plot. 
    actionButton("demoJS", "Using JS", 
     # there is a delay to allow the renderPlot to draw the plot and you should 
     # change it according to the processes performed 
     onclick = "setTimeout(function() { 
        $('html, body').scrollTop($(document).height());}, 
        300)"),   
    # to plot the results after click on "Using JS" 
    uiOutput("plotUI") 
    ) 
), 
    server = shinyServer(function(input, output, session) { 

    output$plot <- renderPlot({ 
     # simple plot to show 
     plot(sin, -pi, 2*pi) 
    }) 

    output$plotUI <- renderUI({ 
     # this UI will show a plot only if "Using JS" is clicked 
     if (input$demoJS > 0) 
     # the margin-top attribute is just to put the plot lower in the page 
     div(style = "margin-top:800px", plotOutput('plot2')) 
    }) 

    output$plot2 <- renderPlot({ 
     # another simple plot, 
     plot(sin, -pi, 2*pi) 
    }) 

    }) 
)) 

당신은 자바 스크립트 옵션이 당신을 위해 잘 작동이라고 생각하면

, 당신은 매우 유용한 기능을 포함하고 당신은 쉽게 당신의 빛나는 Apps로 자신의 자바 스크립트 코드를 추가 할 수 있으며, shinyjs 라이브러리를 사용하기 시작 고려할 수 있습니다.

관련 문제