How to access dataframe from another observeEvent?

后端 未结 1 1793
小蘑菇
小蘑菇 2021-01-24 16:47

An example:

UI.R

library(shiny)    
shinyUI(fluidPage(    
  titlePanel(\"Example\"),    
  sidebarLayout(    
    sidebarPanel(    
      radioButtons(\         


        
相关标签:
1条回答
  • 2021-01-24 17:31

    Not sure what you are trying to accomplish. Maybe you can explain how your app should work. I change your code to show the datasets according to the selected radiobutton. You do not need to put the output inside the observeEvent.

    library(shiny)  
    library(shinyjs)
    
    ui <- shinyUI(fluidPage(
    
      titlePanel("Example"), 
      sidebarLayout( 
        sidebarPanel( 
          radioButtons("orderdata", "Sort by :", 
                       c("Name" = "name", 
                         "MRDNo" = "mrdno"    ))
            ), 
    
        mainPanel( 
          tableOutput("deatilscv") 
        )
      )
    ))
    
    
    server <- shinyServer(function(input, output) {
    
     # observeEvent(input$orderdata,   {
    
          output$deatilscv <- renderTable({ 
    
             if(input$orderdata=="name")   {
    
                mid        <- c("1","2");   name <-c("a","b") 
                datatable <- data.frame(mid,name)  
              #  fluidPage(shinyjs::useShinyjs(), actionButton("button1", "CLICK")  ) 
    
             }  else if(input$orderdata=="mrdno")  {
    
                mid<-c("3","4");  name<-c("c","d") 
                datatable <- data.frame(mid,name) 
               # fluidPage(shinyjs::useShinyjs(),   actionButton("button1", "CLICK")  )
    
             }
    
    
         }) 
      # }) 
    
      # observeEvent(  input$button1,{
      # 
      #              a <- datatable1[1,2]  #this shows an error object 'datatable1' not found 
      #               print(a)
      #            })  
    
      # observeEvent(  input$button2,{ 
      #     a <- datatable2[1,2]  #this shows an error object 'datatable2' not found 
      #     print(a)
      #   })
    })
    
    shinyApp(ui, server)
    
    0 讨论(0)
提交回复
热议问题