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")
    })}

单击“演示”时,会弹出一个消息框,或者我可以使屏幕移动到结果部分并允许文本位于屏幕顶部。

4

1 回答 1

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 代码添加到您的 Shiny 应用程序中。

于 2016-10-02T02:22:31.953 回答