闪亮模块中的observeEvent无法正常工作

时间:2019-05-21 11:57:57

标签: r shiny shinymodules

我正在尝试使用以下示例在我的闪亮应用中实现重置按钮:https://stackoverflow.com/a/44206615/7306168

模块moduleSampleplan确定将使用哪个SamplePlan:默认(从.RData加载到应用程序)或用户定义(从文件加载),并且它提供了“重置”为随时为默认值。

ui.R

sidebar <- dashboardSidebar(

  sidebarMenu(id="sbmenu",
              menuItem('Sample Plan', tabName='sampleplan')
  )
)


body <- dashboardBody(
  tabItems(
    tabItem(tabName='sampleplan', fluidRow(HTML("<div class='HeaderSection'>Sample Plan</div>"),moduleSampleplanUI("sampleplan")))
  )
)

dashboardPage(
  dashboardHeader(  title=div("PROJECT_NAME"), titleWidth=250),
  sidebar,
  body
)

server.R

server = function(input, output) {
  load("/home/beata.gyorgy/Documents/Projects/SHINY_RSQ/Star/SamplePlan.RData")
  source("modules/SPmodule.R")

  dataset = list(SamplePlan=SamplePlan)

  newsp=list()

  newsp <- callModule(moduleSampleplan,"sampleplan",dataset)

}

SPmodule.R

moduleSampleplanUI <- function(id, label = "module Sample Plan") {
  ns <- NS(id)
  tagList(box(
              width=3,
              solidHeader=TRUE,
              status='warning',
              title=div(icon('cog'), div(style='display: inline-block; padding-left: 5px', 'Data selection')),
              fileInput(ns("spfile"),"Upload a new Sample Plan", multiple=F),
              actionButton('resetSP',"Reset Sample Plan")
          )
          ,
          box(
            width=6,
            solidHeader=TRUE,
            status='warning',
            title=div(icon('cog'), div(style='display: inline-block; padding-left: 5px', 'Sample table')),
            uiOutput(ns('sptable'))
          )
  )
}


moduleSampleplan <- function(input, output, session, dataset){


   uploadstatus <- reactiveValues(action = NULL)

   observeEvent(input$spfile, {
      uploadstatus$action = 'upload'

   })

   observeEvent(input$resetSP, {
      uploadstatus$action = 'reset'

   })


   sptable1 <-reactive({

      if (is.null(uploadstatus$action) | uploadstatus$action=="reset"){

         df <- dataset()$SamplePlan
      } 
      else if (uploadstatus$action=="upload"){

         df <- fread(input$spfile$datapath, data.table=F)

      } else { df <- dataset()$SamplePlan     }
      print(df)
      return(df)
   })


   output$sptable <- renderUI({
      output$table1 <- DT::renderDataTable({
         sptable1()
      })
      dataTableOutput("table1")
   })

   rlist = list(sptable=sptable1)
   return(rlist)
}

实际上,似乎没有任何反应,SamplePlan表未显示在应用程序中,也没有显示print(df)

我是一个有模块的新人,所以这里可能很明显缺少我。欢迎任何输入。

0 个答案:

没有答案