2016-10-01 47 views
0

我想讓一個應用程序允許用戶輸入數據,然後讓閃亮的服務器來計算一些結果,例如,我可以讓閃亮的生成一個圖或數據表。問:如何在新頁面中創建閃亮的應用輸出結果?

但是,由於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) 
    }) 

    }) 
)) 

如果你認爲JavaScript的選項爲你工作好,你可以考慮開始使用shinyjs庫,它包括了非常有用的功能,您可以輕鬆地將自己的JavaScript代碼添加到您的閃亮應用。