如何更新用户';R中的数据是什么?

如何更新用户';R中的数据是什么?,r,shiny,R,Shiny,在下面的示例中,我创建了导入演示数据和转到按钮来说明数据格式和输出图。我想知道如果用户上传input$file1aninput$file2等,我如何更新它 rm(list=ls()) library(tidyverse) library(readxl) library(shiny) library(shinyjs) library(shinyWidgets) jsResetCode <- "shinyjs.reset = function() {history.go(0)}" ui &

在下面的示例中,我创建了
导入演示数据
转到
按钮来说明数据格式和输出图。我想知道如果用户上传
input$file1
an
input$file2
等,我如何更新它

rm(list=ls())
library(tidyverse)
library(readxl)
library(shiny)
library(shinyjs)
library(shinyWidgets)

jsResetCode <- "shinyjs.reset = function() {history.go(0)}"

ui <- fluidPage(

  #reset session by reset button
  useShinyjs(),                                           # Include shinyjs in the UI
  extendShinyjs(text = jsResetCode, functions="shinyjs.reset"), 

  #panels
  tabsetPanel(
    ##tabPanel-Input
    tabPanel("Input", fluid = TRUE,

             # tab title ----
             titlePanel("Upload data"),

             # sidebar layout with input and output tables ----
             sidebarLayout(

               # sidebar panel for inputs ----
               sidebarPanel(
                 #show ct demo
                 actionBttn("runexample", "Import demo data", style="simple", size="sm", color = "primary"),

                 # input1: Select a file ----
                 fileInput("file1", "Count matrix File (.xlsx)",
                           multiple = FALSE,
                           accept = c("text/csv",
                                      "text/comma-separated-values,text/plain",
                                      ".csv")),

                 #input2: select a file ----
                 fileInput("file2", "Manifest File (.xlsx)",
                           multiple = FALSE,
                           accept = c("text/csv",
                                      "text/comma-separated-values,text/plain",
                                      ".csv")),

                 #select column name
                 selectInput("design", "Column name for analysis", " "),

                 #select ref group
                 uiOutput("level0"),

                 #select study group
                 uiOutput("level1"),

                 #select column name
                 selectInput("species", "Species", c("Human"="Human", "Mouse"="Mouse")),

                 #action run
                 actionBttn("runbutton", "GO", style="simple", size="sm", color = "primary"),

                 actionBttn("reset", "RESET", style="simple", size="sm", color = "warning"),

               ),
               # Main panel for displaying outputs ----
               mainPanel(
                 # Output: Data file ----
                 span(textOutput("ngene"),style="color:blue"),
                 span(textOutput("nsample"),style="color:blue"),
                 tableOutput("matrix"),
                 tableOutput("pdat")
               )
             )
    ),
    tabPanel("plot", fluid = TRUE,
             plotOutput("plotxy")
    )
  )
)

server <- function(input, output, session) {
  #tabPanel-Input
  ###demo data
  ####count
  ###display demo count matrix
  observeEvent(input$runexample, {
    set.seed(123456)
    n=2000; m=6
    ctobj<- reactive({
      count<-cbind.data.frame(gene=letters[1:20],
                              sample1=rbinom(20, 50, 0.6), 
                              sample2=rbinom(20, 50, 0.6),
                              sample3=rbinom(20, 50, 0.6),
                              sample4=rbinom(20, 50, 0.6),
                              sample5=rbinom(20, 50, 0.6),
                              sample6=rbinom(20, 50, 0.6))
      return(count)
    })

    ####manifest
    pobj<- reactive({
      pheno<-data.frame(ID=paste0("sample", 1:m), 
                        Treatment=rep(c("Dose10", "Control", "Dose20"), each=2), 
                        Gender=sample(c("F", "M"), m, T))
      return(pheno)
    })
    #ngenes
    output$ngene <- renderText({paste("Number of genes: ", dim(ctobj())[1], " [First 10 rows displayed]")})
    #nsamples
    output$nsample <- renderText({paste("Number of samples: ", (dim(ctobj())[2])-1, " [First 10 rows displayed]")})
    #display 10rows count matrix
    output$matrix <- renderTable({
      head(ctobj(), 10)
    })
    #display10rows manifest
    output$pdat <- renderTable({
      head(pobj(), 10)
    })
    #model variables
    ##comparison variable
    observe({
      updateSelectInput(session, "design", choices="Treatment")
    })
    ##ref0
    output$level0 <- renderUI({
      selectInput("ref0", "Reference group", "Control")
    })
    ##ref1
    output$level1 <- renderUI({
      selectInput("ref1", "Study group", "Dose20")
    })
    ##species
    observe({
      updateSelectInput(session, "species", choices="Human")
    })
  })

  observeEvent(input$runbutton, {
    output$plotxy <- renderPlot({
      plot( ctobj()$gene, ctobj()$sample1)
    })
  })
  #RESET for new analysis
  observeEvent(input$reset, {js$reset()}) 
}

shinyApp(ui, server)

在我看来,您只需将第二块放入
observeEvent
环境:

### ALL OF YOUR FIRST CHUNK

observeEvent(input$runbutton, {

  ## YOUR SECOND CHUNK

})
### ALL OF YOUR FIRST CHUNK

observeEvent(input$runbutton, {

  ## YOUR SECOND CHUNK

})