[英]R Shiny: Using variables from output for further calculation outside of function
到目前為止,我的閃亮應用程序外觀如下(摘錄):
ui <- fluidPage(
headerPanel("title"),
sidebarLayout(
sidebarPanel(
h4("header"),
tags$hr(),
# Input: Bilanzpositionen Passiv ----
fileInput("file1", "Kollektive hochladen",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
)
)
)
# # # # #
server <- function(input, output) {
output$contents <- renderTable({
req(input$file1)
bipop <- read.csv(input$file1$datapath,
sep = input$sep,
quote = input$quote)
if(input$disp == "head") {
return(head(bipop))
}
else {
bipop
}
})
}
稍后在代碼(服務器)中,我想從輸入“ bipop”中提取一些數據以創建一些新表,這些表將作為另一個輸出的一部分。
我的審判
monate <- bipop[,4]
不起作用:“錯誤:...未定義的列已選擇...”和“錯誤:對象...未找到”
如何將變量“ bipop”定義為全局變量,以便可以在“輸出”的代碼之外使用它?
謝謝。
為了擴展@ A.Suliman的評論,這是一個完整的示例。
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
h4("header"),
tags$hr(),
# Input: Bilanzpositionen Passiv ----
fileInput("file1", "Kollektive hochladen",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv"))
),
mainPanel(
tableOutput("contents"),
verbatimTextOutput("test")
)
)
)
# # # # #
server <- function(input, output) {
bipop <- eventReactive(input$file1, {
read.csv(input$file1$datapath)
})
output$contents <- renderTable({
bipop()
})
output$test <- renderPrint({
summary(bipop())
})
}
shinyApp(ui, server)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.