dreamRs / esquisse

RStudio add-in to make plots interactively with ggplot2
https://dreamrs.github.io/esquisse
Other
1.76k stars 228 forks source link

esquisse filter functionality to my app #131

Closed mikies21 closed 3 years ago

mikies21 commented 3 years ago

Hi, I have an issues, I would like to use only the filter module in my shiny app. I have a fileInput and as soon as I add it it crashes giving me this error:

Warning in <reactive>(...) : restarting interrupted promise evaluation Warning: Error in data_table: could not find function "data_table"

I work with semi-large datasets. ~300 cols/variables and ~100 rows/samples -input the file use inputfile and read.csv -usually only the first 5 to 10 cols are my metadata, so i make sure they are factors -filter my dataframe on those 5 to 10 cols (this is where esquires is needed and is not working)

heres is my code:


shinyServer(function(input, output, session) {

  filedata_orig <- reactive({
    req(input$datafile)
    infile <- input$datafile
    if (is.null(infile)) {
      # User has not uploaded a file yet
      return(NULL)
    }
    l <- read.csv(infile$datapath)

    return(l)
  })

  items = reactive({
    items1 <- names(filedata_orig)
    names(items1) <- items1
    items1 <- items1[input$columns[1]:input$columns[2]]
    return(items1)
  })

  filedata = reactive({
    df = filedata_orig()
    df[,items()] = as.factor(df[,items()])
    return(df)
  })

  ###esquisse stuff

  res_filter <- callModule(
    module = filterDF, 
    id = "filtering", 
    data_table = filedata(),
    data_name = reactive(input$datafile)
  )
  }
  )
  shinyUI(navbarPage(
  "Data analysis application",

  tabPanel(
    "preparing table",
    titlePanel("data upload and normalisation"),
    fluidPage(sidebarLayout(
      sidebarPanel(
        (fileInput(
          "datafile",
          "Choose CSV File",
          multiple = TRUE,
          accept = c(
            "text/csv",
            "text/comma-separated-values,text/plain",
            ".csv"
          ), placeholder = "UPLOADING.."
        )),
        checkboxInput("metadata", "annotations in first 2 columns () uncheck if more than 2 columns with annotations", value = T),
 conditionalPanel(
          condition = 'input.metadata ==""',
          sliderInput(
            inputId = "columns",
            label = "index column of the first metabolite mesurement?",
            min = 1,
            max = 20,
            step = 1,
            value = c(1, 2)
          )
        ),
        filterDF_UI('filtering'),
        selectInput("normalisation", label = "normalisation", choices = c("None", "PQN", "TotArea", "Bin")),
        selectInput("scaling", label = "scaling", choices = c("None", "Pareto", "Auto", "Range", "Mean"), selected = "Pareto")
      ),
      mainPanel(
        "dataframe",
        DT::dataTableOutput("table1")
        )
      )
    )
  )
  )
  )```
pvictor commented 3 years ago

Hello,

Try without parenthesis when passing reactive function to module, e.g. :

callModule(
  module = filterDF, 
  id = "filtering", 
  data_table = filedata,
  data_name = reactive(input$datafile)
)

Victor

mikies21 commented 3 years ago

Thank you very much! that work, i though i tried that before but aparently I havent! onle last question: if i want to filter only from the first 5 to 10 cols. how would I go about it? I have extracted the column names in the items() variable, I have tried this

callModule(
  module = filterDF, 
  id = "filtering", 
  data_table = filedata,
  data_name = reactive(input$datafile)
  data_vars = items
)

but it is still not working? any advice? thank you very much

pvictor commented 3 years ago

items must be a reactive function returning variable names for which create filters.

For information, I moved this module in package {datamods} (https://dreamrs.github.io/datamods/reference/filter-data.html), the one in {esquisse} will be deprecated in next version.