R Shiny:使用输出中的变量在函数之外进行进一步的计算 [英] R Shiny: Using variables from output for further calculation outside of function

查看:266
本文介绍了R Shiny:使用输出中的变量在函数之外进行进一步的计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我的闪亮应用程序外观如下(提取):

My shiny app looks as follows so far (extract):

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"中提取一些数据以创建一些新表,这些表将作为另一个输出的一部分.

Later on in code (server) I want to extract some data from the Input "bipop" to create some new tables which shall be part of another output.

我的审判

monate <- bipop[,4]

不起作用:错误:...已选择未定义的列..."和错误:未找到对象"

doesn't work: "Error: ... undefined columns selected..." and "Error: object ... not found"

如何将变量"bipop"定义为全局变量,以便可以在输出"的代码之外使用它?

How can I define the variable "bipop" as global, so that I can use it outside of the code from "output"?

谢谢.

推荐答案

为扩展@ A.Suliman的评论,这是一个完整的示例.

To expand @A.Suliman's comment, here is a complete example.

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)

这篇关于R Shiny:使用输出中的变量在函数之外进行进一步的计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆