People!
If i have the following data frame:
observeEvent(input$pesquisa,{
query <- glue(
"select
cod_ordem_producao as ORDEM,
dim_ext_tubo as DIAMETRO,
esp_par_tubo as PAREDE,
cod_aqa as AQA,
tmo_ciclo_plan as CICLO,
dth_criacao_reg as DATA,
dsc_aco as GRAU,
val_lim_escoamento as LE,
val_tensao_residual as TR
from
QT_QTS.PLA_ORDEM_PRODUCAO
where DIM_EXT_TUBO = {as.numeric(input$diametro)}
and esp_par_tubo = {as.numeric(input$parede)}
and tmo_ciclo_plan = {as.numeric(input$ciclo)}
and dth_criacao_reg between DATE '{as.character(input$dates[1])}' and DATE '{as.character(input$dates[2])}'
and VAL_LIM_ESCOAMENTO != 0
order by DTH_CRIACAO_REG desc")
df <- dbGetQuery(
connection_reportUser,
query
)
df <-------------- HERE IS THE SAVED VALUES TO THE DATA FRAME---------------
valor_grau <- df$GRAU
})
And, next, I use another observeEvent:
observeEvent(input$pesquisa, {
insertUI(
selector = "#pesquisa",
where = "afterEnd",
ui = selectInput(
"grau",
label = "Grau:",
choices = valor_grau
)
)
})
Explaining:
I search in a database these values and save into a data.frame (called "df") . When I search for it (with the input's and clicking on the button "pesquisa"), a new field called "Grau:" appear for the user, with new selectable values.
How can I update the "df" with the value from the second input? (in that case, the input from the "insertUI" called "Grau:"
---------------- EDITED ------------------------
In my UI code, i have a: DT::dataTableOutput("contents2")
In server side, i have:
output$contents2 = DT::renderDataTable({
tabela_saida})
My first observeEvent is that described above, and save into my df, than, i have a:
tabela_saida = df
The second observeEvent, should update a value called GRAU in my tabela_saida.
The third observEvent, should update AQA...and so on.
The last of all, should expose the datable updated with all the new values and make a search in my database.
I think you want to update your data.frame according to an entry (grau). To do this, you can create an eventReactive that will execute your query. Within eventReactive you need to check if the user has already selected something in input$grau.
This is a way to do this:
library(shiny)
library(DT)
ui <- fluidPage(
mainPanel(
actionButton(inputId = "pesquisa", label = "pesquisa"),
conditionalPanel(condition = "input.pesquisa > 0", uiOutput("grau")),
DT::DTOutput("contents2")
)
)
server <- function(input, output) {
create_df <- eventReactive(input$pesquisa,{
## Your query about here
## ...
##
df <- data.frame(x = round(rnorm(100), 2), grau = rpois(100, lambda = 10))
grau_values <- unique(df$grau)
if(!is.null(input$grau)){
grau_input <- input$grau
df <- subset(df, grau %in% grau_input)
}
return(list(df = df, grau_values = grau_values))
})
output$grau <- renderUI({
grau_values <- create_df()$grau_values
selectInput(inputId = "grau", label = "Grau:", multiple = TRUE, choices = grau_values, selected = NULL)
})
output$contents2 <- DT::renderDataTable({
df <- create_df()$df
datatable(df, rownames = FALSE)
})
}
shinyApp(ui = ui, server = server)
I hope it works!
Related
I am trying to add a row index column to a reactive data frame created on-the-fly from user inputs. I am able to do this outside of Shiny using the tibble::rowid_to_column function but cannot make it work in the below Shiny app (line 44). Can someone please provide guidance on how to make it work? Also, when I delete a row from the data frame, how can we make rowid numbers sequential again? Thanks.
library(shiny)
library(DT)
library(tidyverse)
input_data <- data.frame(
# rowid = double(),
input1 = character(),
input2 = double(),
stringsAsFactors = FALSE)
ui <- fluidPage(
titlePanel("Title"),
sidebarLayout(
sidebarPanel(
selectInput("input1",
"Input 1",
choices = c("Value 1", "Value 2", "Value 3")),
numericInput("input2",
"Input 2",
value = 100),
actionButton("add_btn",
"Add Row"),
actionButton("delete_btn",
"Delete Row"),
actionButton("reset_btn",
"Reset"),
position = "left"
),
mainPanel(
DT::dataTableOutput("input_table")
)
)
)
server <- function(input, output) {
input_table <- reactiveVal(input_data)
observeEvent(input$add_btn, {
t = rbind(input_table(), data.frame(col1 = input$input1, col2 = input$input2))
# %>%
# cbind(tibble::rowid_to_column("rowid"))
input_table(t)
})
observeEvent(input$delete_btn, {
t = input_table()
print(input$input_table_rows_selected)
if (!is.null(input$input_table_rows_selected)) {
t <- t[-input$input_table_rows_selected,]
}
input_table(t)
})
observeEvent(input$reset_btn, {
input_table(input_data)
})
output$input_table <- DT::renderDataTable({
datatable(input_table())
})
}
shinyApp(ui = ui, server = server)
rowid_to_column() adds the row names of a tibble and adds them as a column to the data frame. This won't work for you: once you have added the rownames in a column rowid, you cannot add that column a second time. Also, the function returns the entire tibble with the new column added, so it makes no sense to cbind() the output of rowid_to_column() it to the tibble.
I suggest the following changes to your code:
Define the initial Table with the rowid column:
input_data <- tibble(
rowid = integer(),
input1 = character(),
input2 = double()
)
In the first observer, change the code to this:
observeEvent(input$add_btn, {
new_row <- tibble(rowid = nrow(input_table()) + 1,
input1 = input$input1,
input2 = input$input2)
t = bind_rows(input_table(), new_row)
input_table(t)
})
This creates a new row with the appropriate rowid and then adds it to the table.
In order to have the expected rowids after deletion of a row you simply have to redefine the rowids each time a row is delted:
observeEvent(input$delete_btn, {
t <- input_table()
print(input$input_table_rows_selected)
if (!is.null(input$input_table_rows_selected)) {
t <- t[-input$input_table_rows_selected, ]
# reset the rowids only, when there is at least one row left
if (nrow(t) > 0) {
t$rowid <- 1:nrow(t)
}
}
input_table(t)
})
And when rendering the output table, you have to suppress the row names:
output$input_table <- DT::renderDataTable({
datatable(input_table(), rownames = FALSE)
})
I've created the Shiny app below:
library(shiny)
library(shinyWidgets)
library(tidyverse)
tbl1 <- tibble(obs = as_factor(letters[1:3]), val = -1:1)
tbl2 <- tibble(obs = as_factor(letters[1:3]), val = 0:2)
flag_outliers <- function(tbl) {
tbl %>% mutate(is_outlier = near(val, min(val)) | near(val, max(val)))
}
ui <- fluidPage(
column(6,
radioButtons("tbl", "Select tibble", choices = c("tbl1", "tbl2")),
actionButton("flag_w_func", "Flag outliers with function"),
pickerInput(
"user_choices", "Flag outliers yourself",
letters[1:3], multiple = TRUE, options = pickerOptions(actionsBox = TRUE)
)
),
column(6, tableOutput("tbl_w_flags"))
)
server <- function(input, output, session) {
tbl <- reactive(switch(input$tbl, tbl1 = tbl1, tbl2 = tbl2))
tbl_w_flags <- reactive(flag_outliers(tbl())) # Not sure what this should be
output$tbl_w_flags <- renderTable(tbl_w_flags())
}
shinyApp(ui, server)
This defines two tibbles, tbl1 and tbl2, and allows the user to choose one; their choice is stored in tbl in the server function. I want to create another tibble in the server function called tbl_w_flags that's tbl plus an is_outlier column.
If the user clicks on the "Flag outliers with function" button, the is_outlier column should be set using flag_outliers(). Also, the dropdown list user_choices should display check marks next to the observations that have been flagged by flag_outliers() and those observations only.
If the user checks or unchecks observations in the dropdown list, the is_outlier column should be updated appropriately - the appropriate values should be changed to TRUE or FALSE.
Thus, tbl_w_flags needs to be modified if the button is clicked or choices are made in the dropdown list, and the dropdown list needs to be modified if the button is clicked.
I don't have much Shiny experience and am struggling to figure out how to do this. Is this possible? If so, how can it be accomplished?
I removed tbl_w_flags and directly updated tbl(), two reactive are not necessary here. I also used reactiveVal for reactive and added an updatePickerInput to also update the picker if the button is clicked
library(shiny)
library(shinyWidgets)
library(tidyverse)
tbl1 <- tibble(obs = as_factor(letters[1:3]), val = -1:1)
tbl2 <- tibble(obs = as_factor(letters[1:3]), val = 0:2)
flag_outliers <- function(tbl) {
tbl %>% mutate(is_outlier = near(val, min(val)) | near(val, max(val)))
}
ui <- fluidPage(
column(6,
radioButtons("tbl", "Select tibble", choices = c("tbl1", "tbl2")),
actionButton("flag_w_func", "Flag outliers with function"),
pickerInput(
"user_choices", "Flag outliers yourself",
letters[1:3], multiple = TRUE, options = pickerOptions(actionsBox = TRUE)
)
),
column(6, tableOutput("tbl_w_flags"))
)
server <- function(input, output, session) {
tbl <- reactiveVal()
observe(tbl(switch(input$tbl, tbl1 = tbl1, tbl2 = tbl2)))
observe(input$user_choices)
observeEvent(input$flag_w_func, {
old_tbl <- tbl()
new_tbl <- flag_outliers(old_tbl)
# Update reactive tbl and user_choice pickerInput
tbl(new_tbl)
new_choices <- new_tbl %>% filter(is_outlier) %>% pull(obs)
updatePickerInput(session, "user_choices", selected = new_choices)
})
observeEvent(input$user_choices, {
old_tbl <- tbl()
new_tbl <- old_tbl %>% mutate(is_outlier = c(obs %in% input$user_choices))
# Update reactive tbl()
tbl(new_tbl)
})
output$tbl_w_flags <- renderTable(tbl())
}
shinyApp(ui, server)
Edit:
If you like to reset the picker whenever the tibble is changed (using the radio buttons), change your first observer to
observe({
tbl(switch(input$tbl, tbl1 = tbl1, tbl2 = tbl2))
updatePickerInput(session, "user_choices", selected = character(0))
})
I understand similar questions have been asked and I've tried virtually every solution with no luck.
In my application, I've allowed the user to modify individual cells of a DT::datatable. The source of the datatable is a reactive data frame.
After the user makes changes to the clientside datatable, the datatable source is remains unchanged. This is an issue as later on, when I allow the user to add rows to the data table, the row is added onto the source datatable where the clientside datatable then reflects this change. However, this means that if the user makes a change to a cell in the clientside datatable, when the user adds a row to the same table, the change made by the user will be forgotten as it was never made to the source.
I've tried many ways to update the underlying/serverside datatable with no luck. editData keeps giving me errors/NA. I also have tried indexing the serverside table and placing the changed value inside of it, with no luck. I'll post my code below with some comments for specifics..
library(shiny)
library(DT)
library(data.table)
source('~/camo/camo/R/settings.R')
source('~/camo/camo/etl.R')
# Define UI ----
ui <- fluidPage(
titlePanel("PAlpha"),
mainPanel(
fluidRow(
tabsetPanel(id = 'tpanel',
type = "tabs",
tabPanel("Alpha", plotOutput("plot1")),
tabPanel("Beta", plotOutput("plot2")),
tabPanel("Charlie", plotOutput("plot3")),
tabPanel("Delta", plotOutput("plot4")))
),
fluidRow(
splitLayout(
dateInput("sdate", "Start Date"),
dateInput("edate", "End Date"),
textInput("gmin", "Global Minimum"),
textInput("gmax", "Global Maximum")
)
),
fluidRow(
splitLayout(
textInput("groupInp", NULL, placeholder = "New Group"),
actionButton("addGrpBtn", "Add Group"),
textInput("tickerInp", NULL, placeholder = "New Ticker"),
actionButton("addTickerBtn", "Add Ticker")
)
),
fluidRow(
splitLayout(
DT::dataTableOutput('groupsTable'),
DT::dataTableOutput('groupTickers')
),
verbatimTextOutput("print")
)
)
)
# Define server logic ----
server <- function(input, output) {
port_proxy <- dataTableProxy('groupsTable')
rv <- reactiveValues(
portfolio = data.frame('Group' = c('Portfolio'), 'Minimum Weight' = c(0), 'Maximum Weight' = c(0), 'Type' = c('-')),
groups = list(group1 = data.frame('Group' = c('Ticker'), 'Minimum Weight' = c(0), 'Maximum Weight' = c(0), 'Type' = c('-'))),
deletedRows = NULL,
deletedRowIndices = list()
)
output$groupsTable <- DT::renderDataTable(
# Add the delete button column
deleteButtonColumn(rv$portfolio, 'delete_button')
)
output$print <- renderPrint({
rv$portfolio
})
############## LISTENERS ################
observeEvent(input$deletePressed, {
rowNum <- parseDeleteEvent(input$deletePressed)
dataRow <- rv$portfolio[rowNum,]
# Put the deleted row into a data frame so we can undo
# Last item deleted is in position 1
rv$deletedRows <- rbind(dataRow, rv$deletedRows)
rv$deletedRowIndices <- append(rv$deletedRowIndices, rowNum, after = 0)
# Delete the row from the data frame
rv$portfolio <- rv$portfolio[-rowNum,]
})
observeEvent(input$addGrpBtn, {
row <- data.frame('Group' = c(input$groupInp),
'Minimum Weight' = c(0),
'Maximum Weight' = c(0),
'Type' = c('-'))
rv$portfolio <- addRowAt(rv$portfolio, row, nrow(rv$portfolio))
})
observeEvent(input$groupsTable_cell_edit,{
info <- str(input$groupsTable_cell_edit)
i <- info$row
j <- info$col
v <- info$value
rv$portfolio <- editData(rv$portfolio, input$groupsTable_cell_edit) # doesn't work see below
# Warning in DT::coerceValue(v, data[i, j, drop = TRUE]) :
# New value(s) "test" not in the original factor levels: "Portfolio"; will be coerced to NA.
# rv$portfolio[i,j] <- input$groupsTable_cell_edit$value
# rv$portfolio[i,j] <- v #doesn't work
})
}
addRowAt <- function(df, row, i) {
# Slow but easy to understand
if (i > 1) {
rbind(df[1:(i - 1), ], row, df[-(1:(i - 1)), ])
} else {
rbind(row, df)
}
}
deleteButtonColumn <- function(df, id, ...) {
# function to create one action button as string
f <- function(i) {
# https://shiny.rstudio.com/articles/communicating-with-js.html
as.character(actionLink(paste(id, i, sep="_"), label = 'Delete', icon = icon('trash'),
onclick = 'Shiny.setInputValue(\"deletePressed\", this.id, {priority: "event"})'))
}
deleteCol <- unlist(lapply(seq_len(nrow(df)), f))
# Return a data table
DT::datatable(cbind(' ' = deleteCol, df),
# Need to disable escaping for html as string to work
escape = FALSE,
editable = 'cell',
selection = 'single',
rownames = FALSE,
class = 'compact',
options = list(
# Disable sorting for the delete column
dom = 't',
columnDefs = list(list(targets = 1, sortable = FALSE))
))
}
parseDeleteEvent <- function(idstr) {
res <- as.integer(sub(".*_([0-9]+)", "\\1", idstr))
if (! is.na(res)) res
}
# Run the app ----
shinyApp(ui = ui, server = server)
As far as I have looked, there is no ready-to-go solution available. You could try to use rhandsontable. It does not provide all the functionality of the DT table, however it allows for the editing. Last time I tried using it there were some minor issues in some edge cases. (Trying to save different data type or something similar.)
Alternatively you can do the stuff manually, along these lines. This is the minimal working example of editing the underlying data frame. Currently I overwrite it every time the user clicks on the table, you would need to change that to handle normal user behavior. It is meant merely as a proof of concept.
library(DT)
library(shiny)
ui <- fluidPage(
DT::dataTableOutput("test")
)
myDF <- iris[1:10,]
js <- c("table.on('click.dt','tr', function() {",
" var a = table.data();",
" var data = []",
" for (i=0; i!=a.length; i++) {",
" data = data.concat(a[i]) ",
" };",
"Shiny.setInputValue('dataChange', data)",
"})")
server <- function(input, output) {
output$test <- DT::renderDataTable(
myDF,
editable='cell',
callback=JS(js)
)
observeEvent(input$dataChange, {
res <- cbind.data.frame(split(input$dataChange, rep(1:6, times=length(input$dataChange)/6)),
stringsAsFactors=F)
colNumbers <- res[,1]
res <- res[,2:ncol(res)]
colnames(res) <- colnames(myDF)
myDF <<- res
print(myDF)
})
}
shinyApp(ui = ui, server = server)
This one has me really going around in circles.
I am working on an R script that loads a dataframe and uses fields from the dataframe to populate a hierarchical set of selectizeInput. E.g. each of the inputs represent a subset of what is in the previous. Each SubRegion contains multiple LCC’s, Each LCC contains multiple ENB’s, and so on.
When the user select a value in any of the inputs, that value will used to filter the dataframe and all of the other selectizeInputs need to be updated from the filtered data.
It seems to work fine for the first input (SubRegionInput) but every time I try to get it to respond to and/or filter by any of the others (e.g. add input$LCCInput to the observe block) they get populated for a few seconds and then go blank.
I suspect the answer is quite simple and/or I am doing something really dumb, but I am a total hack with no formal R training so am probably missing something quite basic (if so sorry).
Below is a partial chunk of code (sorry I can’t include it all but this is for work and I can’t share the details of what I am doing).
NOTES
The current outputs are just so I can see what is going on while I develop this portion of the code.
I know right now it is only set up to filter on the one value…everything I have tried to do it on more has failed so I included the most functional code I have so far.
ui <- fluidPage(
# Application title
titlePanel("KPI DrillDown"),
# Sidebar with a slider input for number of bins
fluidRow(
selectizeInput("SubRegionInput", "SubRegion", SubRegionList ,selected = NULL, multiple = TRUE),
selectizeInput("LCCInput", "LCC", LCCList,selected = NULL, multiple = TRUE),
selectizeInput("ENBIDInput", "ENBID", ENBIDList,selected = NULL, multiple = TRUE),
selectizeInput("SiteNumInput", "SiteNumber", SiteNumberList,selected = NULL, multiple = TRUE),
selectizeInput("SiteNameInput", "SiteName", SiteNameList,selected = NULL, multiple = TRUE),
selectizeInput("LNCELInput", "LNCell", LNCellList,selected = NULL, multiple = TRUE),
selectizeInput("SectorInput", "Sector", SectorList,selected = NULL, multiple = TRUE),
mainPanel(
#plotOutput("distPlot")
verbatimTextOutput("SubRegionText"),
verbatimTextOutput("LCCText"),
verbatimTextOutput("view")
)
)
)
server <- function(input, output) {
observe({
input$SubRegionInput
temp <- SiteInfo[SiteInfo$SITE_SUB_REGION %in% input$SubRegionInput, ]
thisLCCList = sort(temp$BACKHAUL_LCC[!is.na(temp$BACKHAUL_LCC)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "LCCInput"
, choices = thisLCCList
, selected= NULL)
thisENBIDList = sort(temp$ENODEB_ID[!is.na(temp$ENODEB_ID)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "ENBIDInput"
, choices = thisENBIDList
, selected= NULL)
thisSiteNumberList = sort(temp$SITE_NUMBER[!is.na(temp$SITE_NUMBER)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "SiteNumInput"
, choices = thisSiteNumberList
, selected= NULL)
thisSiteNameList = sort(temp$SITE_NAME[!is.na(temp$SITE_NAME)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "SiteNameInput"
, choices = thisSiteNameList
, selected= NULL)
thisLNCellList = sort(temp$SECTOR_NUMBER[!is.na(temp$SECTOR_NUMBER)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "LNCELInput"
, choices = thisLNCellList
, selected= NULL)
thisSectorList = sort(temp$Sector[!is.na(temp$Sector)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "SectorInput"
, choices = thisSectorList
, selected= NULL)
output$view<- renderPrint(temp)
})
Since I do not have access to your data, I used mtcars as an example.
To begin with, since you have so many filtering, I would suggest creating a search or update button, which is what I did in my codes. I only did one filtering using dplyr after extracting all the selectizeInputs. I have to manually change all the empty searching parameter to select all in order to avoid filtering to NA.
Overall, I think the problem with your code was you are observing too many updateSelectizeInputs at once. I did try to recreate using your way, and what I ended with was that I could only update single selectizeInput, and the other selectizeInputs were not selectable.
Hopefully, this method fits your data.
Codes:
library(shiny)
library(dplyr)
library(DT)
data <- mtcars
SubRegionList <- unique(data$cyl)
LCCList <- unique(data$gear)
ENBIDList <- unique(data$am)
SiteNumberList <- unique(data$vs)
# Define UI
ui <- fluidPage(
# Application title
titlePanel("KPI DrillDown"),
# Sidebar with a slider input for number of bins
fluidRow(
selectizeInput("SubRegionInput", "SubRegion/cyl", SubRegionList ,selected = NULL, multiple = TRUE),
uiOutput("LCCInput"),
uiOutput("ENBIDInput"),
uiOutput("SiteNumInput"),
uiOutput("Search"),
mainPanel(
verbatimTextOutput("view")
)
)
)
# Define server logic required
server <- function(input, output, session) {
SiteInfo <- data
# temp <- ""
observe({
if (!is.null(input$SubRegionInput)){
subRegionSelected <- input$SubRegionInput
## Create a temp dataset with the selected sub regions.
temp <- SiteInfo[SiteInfo$cyl %in% subRegionSelected, ]
## Push the newly created selectizeInput to UI
output$LCCInput <- renderUI({
selectizeInput("LCCInput", "LCC/gear", unique(temp$gear), selected = NULL, multiple = TRUE)
})
output$ENBIDInput <- renderUI({
selectizeInput("ENBIDInput", "ENBID/am", unique(temp$am),selected = NULL, multiple = TRUE)
})
output$SiteNumInput <- renderUI({
selectizeInput("SiteNumInput", "SiteNumber/vs", unique(temp$vs), selected = NULL, multiple = TRUE)
})
output$Search <- renderUI({
actionButton("Search", "Search")
})
## Function that linked to the actionButton
display <- eventReactive(input$Search,{
temp <- SiteInfo[SiteInfo$cyl %in% input$SubRegionInput, ]
# ## manually change all the empty searching parameter to select all in order to avoid filtering to NA
LCC <- input$LCCInput
if (is.null(input$LCCInput)){LCC <- unique(temp$gear)}
ENBID <- input$ENBIDInput
if (is.null(input$ENBIDInput)){EBVID <- unique(temp$am)}
SiteNum <- input$SiteNumInput
if (is.null(input$SiteNumInput)){LCC <- unique(temp$vs)}
## Dplyr::filter data
temp <- temp %>%
filter(gear %in% LCC & am %in% ENBID & vs %in% SiteNum)
temp
})
## Run the actionButton
output$view <- renderPrint({
display()
})
} else {
## Display waht the data looks like when no Sub Region is selected
output$view<- renderPrint(data)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
Issues I am having couple of issues with (a) Display the data in interactive mode using Rshiny (2) Querying the results from mongodb Query. My codes are given below, it seems to work as independent pieces but doesnt coalesce well.
For Problem (a), I have previously used Output$values and that seems to work. Commented out in the code
For Problem (b), I have used mongolite R package to query the data and used reactive for passing the query.
library(data.table)
library(tidyverse)
library(shiny)
library(mongolite)
epi <- read.csv("./data/Genes.csv", header=T)
label = "gene"
epilist <- data.frame(epi$gene, label)
names(epilist) = c("value", "label")
df <- read.table("./data/CCLE_meta.csv", header=TRUE, sep=",", na.strings="NA", fill=TRUE)
dd <- data.frame((df$Tissue))
names(dd) = "Tissue"
cell1= dd %>% add_row(Tissue = "all")
label = "Tissue"
cell <- data.frame(cell1$Tissue, label)
names(cell) = c("value", "label")
ui <- fluidPage(
titlePanel("Dependencies for EpiGenes"),
sidebarLayout(
sidebarPanel(
selectizeInput("epiInput","gene", choices=NULL, selected=NULL),
selectizeInput("cellInput","Tissue", choices=NULL, selected=NULL),
textOutput("values")
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Fusions", tableOutput("table")),
tabPanel("CancerGD", tableOutput("table")),
tabPanel("CCLEmeta", tableOutput("table")),
tabPanel("EpiGenes", tableOutput("table"))
)
)
)
)
server <- function(input, output, session) {
updateSelectizeInput(session, 'epiInput',
choices = epilist$value,
server = TRUE)
updateSelectizeInput(session, 'cellInput',
choices = cell$value,
server = TRUE)
#output$values <- renderText({
# paste(input$epiInput, input$cellInput)
#})
### Looking into Epi Genes
con1 <- mongo(collection = "Genes", db = "discovery", url = "mongodb://127.0.0.1:27017")
data.for.table1 <- reactive({
query.foo <- paste0('{"gene" : epiInput}')
con1$find(query = query.foo, limit = 100)
})
output$EpiGenes <- renderDataTable({
data.for.table1()
})
### Looking into Cell Line Metadata
con0 <- mongo(collection = "CellLine", db = "discovery", url = "mongodb://127.0.0.1:27017")
data.for.table0 <- reactive({
query.foo <- paste0('{"Tissue" : input$cellInput}')
con0$find(query = query.foo, limit = 100)
})
output$CCLEmeta <- renderDataTable({
data.for.table0()
})
### Looking into fusion genes
con2 <- mongo(collection = "fusions", db = "discovery", url = "mongodb://127.0.0.1:27017")
data.for.table2 <- reactive({
query.foo <- paste0('{"gene" : input$epiInput}')
con2$find(query = query.foo, limit = 100)
})
output$Fusions <- renderDataTable({
data.for.table2()
})
### Looking into CancerGD
con3 <- mongo(collection = "CancerGD", db = "discovery", url = "mongodb://127.0.0.1:27017")
data.for.table3 <- reactive({
query.foo <- paste0('{"gene" : input$epiInput}')
con3$find(query = query.foo, limit = 100)
})
output$CancerGD <- renderDataTable({
data.for.table3()
})
# Automatically disconnect when connection is removed
rm(con0)
rm(con1)
rm(con2)
rm(con3)
gc()
}
shinyApp(ui, server)
The first expected output is an app to allow users to query from the list of genes and tissue. The second expected output is display query results in its appropriate tab (From 4 collections from database discovery). The current result is an app with no ability to query.
I was able to make some changes to the code and the error/hanging I now get is
"Imported 0 records. Simplifying into dataframe..."
Any insight into the error will be helpful.
The improvements to the codes are as follows;
(a) SidebarPanel
selectizeInput("epiInput","gene", choices=gg),
selectizeInput("cellInput","Tissue", choices=cc),
(b) Connecting to MongoDB
con2 <- mongo(collection="fusions", db="discovery", url="mongodb://localhost:27017", verbose = TRUE)
fusResults <- reactive({
region <- list(gene = input$epiInput)
query.foo <- paste0('{ "gene" : "',region , '"}')
fs <- con2$find(query = query.foo, limit = 100)
return(fs)
})
output$fus_results <- renderDataTable({
fusResults()
})