gpt4 book ai didi

R Shiny Tabsets 同时处理

转载 作者:行者123 更新时间:2023-12-04 02:29:48 24 4
gpt4 key购买 nike

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

这是 Shiny[教程]:( http://www.http://rstudio.github.io/shiny/tutorial/#more-widgets/ )

中的修改示例

用户界面:

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

)
)
))

服务器.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)

将其放入您的服务器.R。让我(我们)知道这是否如您所愿。

文档:

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

关于R Shiny Tabsets 同时处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21757876/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com