Allow user to select columns from global env dataset in rstudioaddin

Hello
I am trying to work on an addin, and I need to:

1- allow users to select a dataset from the global environment (this part I was able to figure out using the instructions from this post How can I access the user's global environment? )

2- all the user to select multiple columns of the dataset to display (and eventually analyze).
I copied this example from the post I mentioned and made some changes but still unable to figure it out. How would I use the names of the variables as choices under selectizeInput?

thank you

library(shiny)
library(miniUI)
library(purrr)
library(dplyr)
library(rstudioapi)


# Get contents of GlobalEnv
get_ge <- ls(envir = globalenv())
dd <- map(get_ge, get) # get object contents
names(dd) <- get_ge
# Keep only data.frames
dd <- dd[map_lgl(dd, inherits, what = 'data.frame')]



####### 



test_app <- function() {
  # Get contents of GlobalEnv
  get_ge <- ls(envir = globalenv())
  dd <- map(get_ge, get) # get object contents  
  names(dd) <- get_ge
  # Keep only data.frames
  dd <- dd[map_lgl(dd, inherits, what = 'data.frame')]
  
  ui <- miniPage(
    gadgetTitleBar("Can you hear me?"),
    miniContentPanel(
      selectInput('choose', 'Choose data to display',
                  choices = names(dd)),
      
      selectizeInput(
        inputId = 'vars',
        label = 'select variables',
        choices = names(dd[[input$choose]]),  #how to allow used to pick from the variables in the selected dataset? 
        multiple = TRUE
      ),
     
      
      tableOutput('show_me')
    )
  )
  
  
  ######################
  server <- function(input, output, session) {
    
    
    
    output$show_me <- renderTable({
      req(input$choose)
      sel.df = as.data.frame(dd[[input$choose]])
      
      sel.df %>% dplyr:: select(input$vars)  #here I am trying to subset the dataset
    })
  }
  
  
  ##################
  viewer <- dialogViewer('Test')
  runGadget(ui, server, viewer = viewer)
}

test_app()

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.