r - 页面加载时 Shiny 的 submitButton 行为

标签 r shiny

提交按钮很有用,但我还没有找到一种优雅的方法来抑制初始页面加载时的输出。

例如,Shiny 教程在加载时呈现输出。
http://rstudio.github.com/shiny/tutorial/#more-widgets

如何确保在按下提交按钮之前不会调用任何 react 性函数?

这是上面链接的示例的内联代码。

#ui.R
library(shiny)

# Define UI for dataset viewer application
shinyUI(pageWithSidebar(

  # Application title.
  headerPanel("More Widgets"),

  # Sidebar with controls to select a dataset and specify the number
  # of observations to view. The helpText function is also used to 
  # include clarifying text. Most notably, the inclusion of a 
  # submitButton defers the rendering of output until the user 
  # explicitly clicks the button (rather than doing it immediately
  # when inputs change). This is useful if the computations required
  # to render output are inordinately time-consuming.
  sidebarPanel(
    selectInput("dataset", "Choose a dataset:", 
                choices = c("rock", "pressure", "cars")),

    numericInput("obs", "Number of observations to view:", 10),

    helpText("Note: while the data view will show only the specified",
             "number of observations, the summary will still be based",
             "on the full dataset."),

    submitButton("Update View")
  ),

  # Show a summary of the dataset and an HTML table with the requested
  # number of observations. Note the use of the h4 function to provide
  # an additional header above each output section.
  mainPanel(
    h4("Summary"),
    verbatimTextOutput("summary"),

    h4("Observations"),
    tableOutput("view")
  )
))



#server.R
library(shiny)
library(datasets)

# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {

  # Return the requested dataset
  datasetInput <- reactive({
    switch(input$dataset,
           "rock" = rock,
           "pressure" = pressure,
           "cars" = cars)
  })

  # Generate a summary of the dataset
  output$summary <- renderPrint({
    dataset <- datasetInput()
    summary(dataset)
  })

  # Show the first "n" observations
  output$view <- renderTable({
    head(datasetInput(), n = input$obs)
  })
})

最佳答案

一种方法是使用 actionButton (来自 shiny-incubator 包)和 isolate . Here's一篇解释如何将两者结合使用的文章。这是一种本质上比 submitButton 更灵活的方法,这有点过于严厉,不够灵活。

关于r - 页面加载时 Shiny 的 submitButton 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15840803/

相关文章:

r - Shiny 的 R renderTable 右对齐

尽管没有任何错误,但 Renderplotly 不起作用

来自检查数据表中的行的 RStudio Shiny 列表

r - 使用 DT 在 Shiny 中选择单行

r - 在 ggplot 中使用 ..prop.. 时如何为条形图着色?

r - R中任何天数基础的日期之间的天数

r - 如何使用线条符号回收 colorbrewer 调色板中的颜色

从 R 中的 url 返回根域

r - 在 data.table (R) 中按组高效生成随机变量

Radiant R 无法在 Shiny 的服务器上运行