3
我有一個R Shiny
應用程序,它可以計算不同標籤集中的多個統計信息。由於計算量非常大,我使用submitButton
來防止反應。我的問題是現在每個計算(全部在不同的製表符集)正在將輸出寫入一個文件夾,並且我希望Shiny
在初始化時爲所有制表符寫入輸出。不幸的是,Shiny
只會爲標籤集創建一個輸出,它在初始化時處於活動狀態。有沒有辦法告訴Shiny
,它應該在初始化時爲每個選項卡計算/渲染輸出?R Shiny Tabsets同時處理
下面是從Shiny
[教程]修改例:(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")
})
})
感謝@Vincent,它確實適用於我已經發布,但不幸的是在我的應用只有我的四個tabsets的前兩個按預期工作,雖然我已經定義'的例子outputOptions'所有四個輸出。這真的很奇怪。但它可能適用於其他人,所以+1。 –
如果你可以做一個簡單的可重複使用的例子,那麼你可能需要將它發佈到[Shiny discussion group](https://groups.google.com/forum/?fromgroups=#!forum/shiny-discuss)或者作爲Github上的[Issue](https://github.com/rstudio/shiny/issues?state=open)。 – Vincent