本文介绍了R Shiny Tabsets 同时处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 R Shiny 应用程序,它计算不同标签集中的几个统计数据.由于计算非常密集,我使用 submitButton 来防止反应性.我现在的问题是每个计算(都在不同的标签集中)将输出写入文件夹,我希望 Shiny 在初始化时为所有标签集编写输出.不幸的是,Shiny 只为标签集创建一个输出,它在初始化时是活动的.有没有办法告诉 Shiny,它应该在初始化时为每个选项卡计算/渲染输出?

I have a R Shiny app, which calculates several statistics in different tabsets. As the calculations are quite computation intensive, I use submitButton to prevent reactivity. My problem is now that each calculation (all in different tabsets) are writing outputs to a folder and I want Shiny to write an output for all tabsets when initializing. Unfortunately, Shiny only creates an output for the tabset, that is active when initializing. Is there a way to tell Shiny, that it should calculate/render outputs for every tab when initializing?

这是 Shiny[教程] 中的修改示例:(http://www.http://rstudio.github.io/shiny/tutorial/#more-widgets/)

Here is a modified example from the Shiny[Tutorial]:(http://www.http://rstudio.github.io/shiny/tutorial/#more-widgets/)

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(
    tabsetPanel(
      tabPanel("Summary", verbatimTextOutput("summary")),
      tabPanel("Table", 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()

    capture.output(summary(dataset),file="summary.txt")

  })

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

    capture.output(a,file="table.txt")

  })
})

推荐答案

我想你想要:

outputOptions(output, "summary", suspendWhenHidden = FALSE)
outputOptions(output, "view", suspendWhenHidden = FALSE)

把它放到你的 server.R 中.让我(我们)知道这是否如您所愿.

Put this into your server.R. Let me (us) know if this works as you expect.

文档:

http://www.inside-r.org/packages/cran/shiny/docs/outputOptions

这篇关于R Shiny Tabsets 同时处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 12:35