r - Empty textInput() causing error in leaflet shiny app - r

I have a shiny app that plots data from an API on a leaflet map. It also takes 2 inputs from the user that are passed through to the API call.
One of those is a text input that sets the region for which the API should pull data. If the user types in an incorrect region code or simply deletes the code, the shiny app gives an error and then you have to type in a correct code and wait for the app to get back on track. It's clumsy and looks bad.
I tried to get around it by using if(is.null(APIdata())) with an if{}else{} (see code below), but this literally did not change anything. I thought it would work, and I'm fine with the idea of it just popping back to an empty leaflet. Is there something else I can do?
Error:
Error: parse error: premature EOF
(right here) ------^
and
Warning: Error in : parse error: premature EOF
(right here) ------^
Stack trace (innermost first):
96: parse_string
95: parseJSON
94: fromJSON_string
93: jsonlite::fromJSON
92: ebird_GET
91: ebirdnotable
90: <reactive:APIdata> [/Users/Guest/Desktop/eBirdRarity/app.R#41]
79: APIdata
78: func [/Users/Guest/Desktop/eBirdRarity/app.R#68]
77: origRenderFunc
76: output$myMap
1: runApp
Code:
library(shiny)
library(shinydashboard)
library(shinythemes)
library(leaflet)
library(leaflet.extras)
library(rebird)
ui <- bootstrapPage(
theme = shinytheme("superhero"),
# Setting map to full-screen
tags$style(type="text/css", "html, body {width:100%;height:100%}"),
# Initializing leaflet output
leafletOutput("myMap", width="100%", height="100%"),
# Adding title overlayed on leaflet map
absolutePanel(top = 1, left = 50, draggable = T,
titlePanel("eBird Recent Rarities Viewer")),
# Adding slider input overlayed on leaflet map
absolutePanel(bottom = 1, left = 45, draggable = T,
sliderInput("slider_in", "Days Back", min = 1, max = 30, value = 14, round = T)),
# Adding text input overlayed on leaflet map
absolutePanel(top = 1, right = 45, draggable = T,
textInput("region_in", "Region Code", value = "US-MA", placeholder = "US-MA"))
)
server <- function(input, output) {
# Rendering data frame from API with slider input
APIdata <- reactive({
# Initial fetch of data from eBird API
a <- ebirdnotable(region = as.character(input$region_in), back = as.numeric(input$slider_in))
# Changing review status from logical to numeric
cols <- sapply(a, is.logical)
a[,cols] <- lapply(a[,cols], as.numeric)
# Initializing new date column
a["date"] <- format(strptime(a$obsDt, format = "%Y-%m-%d"), "%b %d")
# Initializing new color grouping column
a["group"] <- NA
# Assigning colors by review status
idx<- (a$obsReviewed == 0) # Not reviewed
a$group[idx] <- "white"
idx<- (a$obsReviewed == 1) & (a$obsValid == 1) # Reviewed and accepted
a$group[idx] <- "green"
# Jittering lat/lon points to fix point overlap
a$lat = jitter(a$lat, factor = 3)
# print(a)
return(a)
})
# Leaflet map
output$myMap = renderLeaflet({
if(is.null(APIdata()))
{
# Rendering leaflet map
return(leaflet() %>% addTiles()) %>%
addSearchOSM(options = searchOSMOptions(zoom = 8))
}
else
{
# Splitting up by review status in order to show reviewed on top
notReviewed = APIdata()[APIdata()$group == "white",]
accepted = APIdata()[APIdata()$group == "green",]
# Rendering leaflet map
leaflet() %>% addTiles() %>%
addCircleMarkers(data = notReviewed, color = "white", opacity = 0.7, label = paste(notReviewed$comName,", ",notReviewed$date, ", ", notReviewed$locName,sep = "")) %>% # , labelOptions = labelOptions(noHide = F, direction = 'auto')) %>%
addCircleMarkers(data = accepted, color = "green", opacity = 0.7, label = paste(accepted$comName,", ",accepted$date, ", ", accepted$locName, sep = "")) %>% # , labelOptions = labelOptions(noHide = F, direction = 'auto')) %>%
addLegend(position = "bottomright",
colors = c("#FFFFFF", "#008000"),
labels = c("Not reviewed", "Accepted"),
title = "Legend: review status", opacity = 1) %>%
addSearchOSM(options = searchOSMOptions(zoom = 8))
}
})
}
# Run the application
shinyApp(ui = ui, server = server)

You could just validate if you are getting a tibble with values or if you are getting an empty tibble. In case the tibble is empty you can return NULL. This way the validation you have added to check if APIdata() is NULL would work.
You could just add if(length(a) == 0){return(NULL)} after a <- ebirdnotable(region = as.character(input$region_in), back = as.numeric(input$slider_in)) in your reactive for it to work.
EDIT:
As you mentioned in your comment you can actually use try here. That would mean adding one more condition in addition to above condition the code would be something like this:
a <- try(ebirdnotable(region = as.character(input$region_in), back = as.numeric(input$slider_in)))
if(class(a) == "try-error" ||length(a) == 0){return(NULL)}
Hope it helps!

Related

Leaflet map crashes on recoloring after translation (Shiny, Leaflet, shiny.i18n)

I'm currently trying to make a Shiny app for Leaflet cards with simple translations. Each leaflet card has several base groups that are linked to different variables. To avoid re-rendering the leaflet maps every time the base group changes, I have adopted a function I found here which only changes the fill of the polygons.
As long as I only use one language, the app works without problems, but when multiple translations options are implemented, the app crashes. The problem seems to occur when I try to link input$map_groups to variables needed for colouring.
My code looks like this:
library(shiny)
library(shinyWidgets)
library(leaflet)
library(sf)
library(dplyr)
library(shiny.i18n)
#--- Loading Generic Shape File For Demonstration
shape <- st_read(system.file("shape/nc.shp", package = "sf"),
stringsAsFactors = FALSE) %>%
#--- Mutating Two Variables To Factors As My Map Uses Factors
mutate(One = as.factor(SID74), Two = as.factor(SID79)) %>%
#--- Keep Just This Three Variables
select(c(CNTY_ID, One, Two))
#--- Color Palette For Filling Polygons
scale.color <- colorFactor(palette = "RdYlBu", levels = seq(1:60))
#--- Loading And Rgistering Translation File
lang <- Translator$new(translation_json_path = "./translations.json")
lang$set_translation_language("gb")
language <- c("English", "Deutsch", "Français" , "Español")
#--- Naming Vector For Base Groups And Related Variables
layer_calls <- setNames(c('One', 'Two'), c("First", "Second"))
#--- A Function For Recoloring An Existing Polygon And Related JS-Code
#----- Source: https://github.com/rstudio/leaflet/issues/496#issuecomment-650122985
setShapeStyle <- function(map, data = getMapData(map), layerId, stroke = NULL, color = NULL, weight = NULL,
opacity = NULL, fill = NULL, fillColor = NULL, fillOpacity = NULL, dashArray = NULL,
smoothFactor = NULL, noClip = NULL, options = NULL){
options <- c(list(layerId = layerId),
options,
filterNULL(list(stroke = stroke, color = color, weight = weight, opacity = opacity,
fill = fill, fillColor = fillColor, fillOpacity = fillOpacity,
dashArray = dashArray, smoothFactor = smoothFactor, noClip = noClip)))
# Evaluate All Options
options <- evalFormula(options, data = data)
options <- do.call(data.frame, c(options, list(stringsAsFactors = FALSE)))
layerId <- options[[1]]
style <- options[-1] # drop layer column
leaflet::invokeMethod(map, data, "setStyle", "shape", layerId, style);
}
leafletjs <- tags$head(
tags$script(HTML(
'
window.LeafletWidget.methods.setStyle = function(category, layerId, style){
var map = this;
if (!layerId){
return;
} else if (!(typeof(layerId) === "object" && layerId.length)){ // in case a single layerid is given
layerId = [layerId];
}
//convert columnstore to row store
style = HTMLWidgets.dataframeToD3(style);
//console.log(style);
layerId.forEach(function(d,i){
var layer = map.layerManager.getLayer(category, d);
if (layer){ // or should this raise an error?
layer.setStyle(style[i]);
}
});
};
'
)))
#--- Defining UI
ui <- fluidPage(
leafletjs,
usei18n(lang),
pickerInput(inputId = 'selected_language', width = 125,
choices = c("gb", "de", "fr", "es"),
selected = lang$get_key_translation()),
leafletOutput("map")
)
#--- Defining Server Logic
server <- function(input, output, session){
output$map <- renderLeaflet({
leaflet(data = shape) %>%
#--- Initial Unfilled Polygon Map
addPolygons(layerId = ~CNTY_ID, stroke = TRUE, color = "white", weight = 1.25,
highlightOptions = highlightOptions(stroke = 5, weight = 10)) %>%
#--- Initial Layer Controls
addLayersControl(baseGroups = lang$t(names(layer_calls)))
})
#--- Filling Polygons Based On Base Layer-Variable After Translation
observe({
req(input$selected_language)
update_lang(session, input$selected_language)
leafletProxy("map", data = shape) %>%
#--- This Part Always Crashes Shiny!!!
setShapeStyle(layerId = ~CNTY_ID, fillOpacity = 1)#, fillColor = ~scale.color(get(layer_calls[lang$t(input$map_groups)])))
})
}
# Run the application
shinyApp(ui = ui, server = server)
My basic translation scheme would be provided by a JSON file which looks like this:
{
"languages": [
"gb",
"de",
"fr",
"es"
],
"translation": [
{
"gb": "First",
"de": "Erste",
"fr": "Premier",
"es": "Primera"
},
{
"gb": "Second",
"de": "Zweite",
"fr": "Deuxième",
"es": "Segundo"
}
]
}
In my One-Langue-App I can simply use , fillColor = ~scale.color(get(layer_calls[[input$map_groups]])) to trigger a recoloring after the base group has been changed. Unfortunately, I have no idea how to connect the selected base group to a call of the needed variable to trigger the recoloring. Any kind of help is greatly appreciated!

Can’t display error bars with Plotly and Shiny

I’m trying to display error bars on a scatter plot with Shiny and plotly. Here’s my code in my server.R file:
data = reactiveVal()
observe({
results <- data.frame() # actually getting the data from here
# formatting output
final.results <- cbind(
"id" = paste(results$a,
results$b,
results$c,
sep = '-'),
"sigma" = sprintf("%.5g", results$s),
"c-e" = sprintf("%.3g",results$calc - results$exp)
)
data(final.results)
})
output$plot <- renderPlotly(
as.data.frame(data()[,c("id", "c-e", "sigma")]) %>% plot_ly(
x = ~`c-e`,
y = ~id,
height = 800,
type = 'scatter',
mode = 'markers',
marker = list(color = "#90AFD9"),
error_x = list(array = ~sigma, color = "#000000", type = "data")
)
)
The plot is ok except it’s not showing the error bars, what’s my mistake ?
EDIT: clarification for the origin of the data() function and what it’s return value is.
Thesprintf() function returns a character string, not a number, that is why it is not displaying the sigma values as error bars. If you want to keep 5 decimal places, use the round() function instead:
"sigma" = round(results$s, digits = 5)

How to solve the error in highcharOutput in shiny tool?

I'm working on cancer data from TCGA.
Im new to shiny and creating web applications (learning it!!)
I'm working on a shiny tool to plot the volcanoplot using highcharter package.
sometimes I'm successfully able to plot the volcanoplot in the UI. but sometimes it fails to plot it and throws an error saying,
"An error has occurred!
could not find function "highchartOutput"
and one warning message is given for the error;
Listening on http://127.0.0.1:5335
Warning: Error in highchartOutput: could not find function "highchartOutput"
83: dots_list
82: div
81: tabPanel
I think there is some problem with the tabset panel.
is this error has anything to do with indentation? (wherever I adjust the brackets it works magically. not sure how it works for sometimes.)
I am attaching the UI and server files with this post.
code is attached for one type of comparison
UI file below:
library(shiny)
# Define UI for application
shinyUI(fluidPage(
# Application title
titlePanel("miR-Gyn-Explorer"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
## select the count matrix
selectInput("file", label = h3("Count Matrix"),
choices = list("Stage I - Normal" = list("TCGA-BRCA" = "Data/TCGA-BRCASI_NT.rda", "TCGA-UCEC" = "Data/TCGA-UCECSI_NT.rda"))),
## select the phenodata of samples
selectInput("phenofile", label = h3("Sample Phenodata"),
choices = list("Stage I - Normal" = list("TCGA-BRCA" = "Data/TCGA-BRCA_phenoSI_NT.rda", "TCGA-UCEC" = "Data/TCGA-UCEC_phenoSI_NT.rda"))),
submitButton("Update View")
),
# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
tabPanel("DEmiRNA", DT::dataTableOutput("DEmiRNA"),
"Volcano-Plot", highchartOutput("volcanoPlot", height = "500px"))
#tabPanel("miRNA-Targets", DT::dataTableOutput('miRTarget'),
#plotOutput("GO"))
)
)
)
)
)
server file:
library(shiny)
library(R.utils)
##function to find the DEmiRNA by edgeR method
library(limma)
library(edgeR)
library(DT)
library(dplyr)
library(multiMiR)
library(miRBaseConverter)
library(ggplot2)
#library(ggrepel)
library(tidyverse)
library(highcharter)
library(org.Hs.eg.db)
library(clusterProfiler)
library(purrr)
gdcDEmiRNA <- function(counts, groups, comparison, filter=TRUE) {
## method = edgeR
dge = DGEList(counts = counts, samples = groups)
group <- factor(groups$group)
design <- model.matrix(~0+group)
colnames(design) <- levels(group)
contrast.matrix <- makeContrasts(contrasts=comparison,
levels=design)
keep = filterByExpr(dge,design)
dge <- dge[keep,,keep.lib.sizes = TRUE]
dge <- calcNormFactors(dge)
dge <- estimateDisp(dge, design)
fit <- glmFit(dge, design)
lrt <- glmLRT(fit, contrast=contrast.matrix)
DEGAll <- lrt$table
DEGAll$FDR <- p.adjust(DEGAll$PValue, method = 'fdr')
o <- order(DEGAll$FDR)
DEGAll <- DEGAll[o,]
return (DEGAll)
}
# Define server logic required to perform the DEmiRNA analysis
server <- function(input, output) {
d <- reactive({
#DEmiRNA calculation
file <- load(input$file)
phenofile <- load(input$phenofile)
if(file == "SI_NT"){
if(phenofile == "phenoSI_NT"){
DEmiRNA <- gdcDEmiRNA(counts = SI_NT, groups = phenoSI_NT,
comparison = 'StageI-Normal')
}
}
})
output$DEmiRNA <- DT::renderDataTable({
mir <- d()
#mir <- mir[mir$FDR < input$FDR,]
})
output$volcanoPlot <- renderHighchart({
x <- d()
x$mirna <- rownames(x)
x$sig <- ifelse(x$PValue < 0.05 & abs(x$logFC) > 0.57, "DEmiRNA", "Not Regulated")
hc <- highchart() %>%
hc_add_series(x, "scatter", hcaes(logFC, -log10(PValue), group = sig, value = mirna),
color = c('rgba(67, 67, 72, 0.6)', 'rgba(124, 181, 236, 0.6)'),
enableMouseTracking = c(TRUE, TRUE),
showInLegend = TRUE, marker = list(radius = 4)) %>%
hc_tooltip(pointFormat = "{point.value}", headerFormat = "") %>%
hc_xAxis(title = list(text = "Log fold change"), gridLineWidth = 1,
tickLength = 0, startOnTick = "true", endOnTick = "true", min = -6, max = 6) %>%
hc_yAxis(title = list(text = "-Log10(p-value)")) %>%
hc_chart(zoomType = "xy", width=700) %>%
hc_exporting(enabled = TRUE, filename = "volcano")
hc
})
}
any comment and help from you guys is appreciated
Thank you in advance!
-Ankita

Selecting point with shiny and plotly

I have been trying for some time to debug my Shiny gadget but still cannot manage it. Really appreciate any help.
My gadget consists of a scatterplot generated with Plotly. The user can click one of the points, which will allow you to change some parameters associated with that point. To emphasise the fact that the user has selected that point, I wanted to highlight the selected point.
Alternatively, the user can also select a point from a dropdown menu, which also should highlight the corresponding point.
As an added feature, I want to additionally highlight points that are below a certain threshold on the x axis. This threshold is represented by a dotted line, which you can turn on and off, and move the value of the threshold.
In summary, the points on the plot should all be blue circles, except for the following two cases:
if it is clicked, i.e. it is the "active point" (this should create a red border around the point)
if it is below the threshold on the x-axis (the point should turn to an orange square)
If it is active AND below the threshold, it should be an orange square with a red border, as you would expect.
My gadget works, kind of. But in some cases not. In the example below, one of the points is already below the threshold, but when I select that point, the red marker appears on another point! Despite the active variable being the correct one.
I also get a weird behaviour that the points turn purple if the threshold is below all of the points. But if I move the threshold to be above one of the points, the colours are corrected.
I have a suspicion that this is something to do with the points being on different traces? Therefore when I try to highlight certain points, perhaps I am not indexing the vector as I am expecting. But I am finding it really difficult to debug inside Shiny and Plotly, and I have no good understanding of the Plotly object, so I don't have much clue as to what is going on.
The code below is a reproducible example. You have to run "dat1" through the "rew8r" function. I have taken out other features of the app to try to focus on the problem. Thanks very much to anyone who might take the time to have a look at this, and give any hints!
library(plotly)
library(dplyr)
library(shiny)
library(reactable)
dat1 <- data.frame(
Indicator = c("v1","v2","v3"),
Weight = rep(1,3),
Correlation = c(0.1, 0.8, 0.6) )
rew8r <- function(dat){
# get indicator names
inames <- dat$Indicator
## Create the shiny UI layout
ui <- fluidPage(
# the side panel
sidebarPanel(
selectInput("vseldrop", "Select indicator here or by clicking a point on plot.",
c("<Select>",inames)),
hr(style = "border-top: 1px solid #000000;"),
fluidRow(
column(6,numericInput("locorval", "Low correlation threshold:", 0.2, min = -1, max = 1, step = 0.05)),
column(6,br(),checkboxInput("locorsw", "Enable", value = FALSE)))
),
# the main panel (graph, table, etc)
mainPanel(
plotlyOutput("corrplot"),
textOutput("info")
)
)
## Create the Shiny Server layout
server <- function(input, output, session) {
# this is the plotly click data
event.data <- reactive({event_data(event = "plotly_click", source = "scplot")})
# First, monitor which variable is active
# Create reactive value for active var
acvar <- reactiveVal(NULL)
# update active variable via plot click
observeEvent(event.data(),{
acvar(event.data()$key)})
# update active variable via dropdown
observeEvent(input$vseldrop,
acvar(input$vseldrop))
## Create the plotly plot that compares price vs scoops
output$corrplot <- renderPlotly({
# colours around markers when selected or not
lincol <- ifelse(inames %in% acvar(), "red", "blue")
# size of line around marker (set to 0 if not selected)
linsize <- ifelse(inames %in% acvar(), 3, 0)
# symbol when above/below corr threshold
symbs <- if(input$locorsw==TRUE){c(16,15)}else{c(16,16)}
# colour when above/below threshold
pcols <- if(input$locorsw==TRUE){c("blue", "orange")}else{c("blue", "blue")}
# generate main plot
p <- plot_ly(dat, x = ~Correlation, y = ~Weight, type = "scatter", mode = "markers",
text = ~Indicator, key = ~Indicator, source = "scplot",
marker = list(size = 10, line = list(color = lincol, width = linsize)),
symbol = ~Correlation < input$locorval, symbols = symbs,
color = ~Correlation < input$locorval, colors = pcols) %>%
layout(showlegend = FALSE, yaxis = list(
range = c(0, 1.25),
autotick = FALSE,
dtick = 0.25),
xaxis = list(
range = c(-0.5, 1),
autotick = FALSE,
dtick = 0.2))
# add low correlation line, if activated
if(input$locorsw==TRUE){
p <- p %>% add_segments(x = input$locorval, xend = input$locorval, y = 0, yend = 1.25,
marker = list(color = 'red', opacity=0),
line = list(dash = 'dash')) %>%
layout(showlegend = FALSE)
}
p
})
# Text info
output$info <- renderText({
paste(acvar(), class(acvar()))
})
# update dropdown menu
observeEvent(acvar(),{
updateSelectInput(session, "vseldrop", selected = acvar())
})
}
runGadget(ui, server, viewer = browserViewer())
}

Using an IF statement on a reactive variable inside an observe context

I am trying to create a shiny flexdashboard within R Markdown that will display different tables based on user input. Some tables are formattable, others are just regular tables. The following code will do the rendering of the table if the tables in a list are all Formattables.
num <- reactive(as.integer(input$qualityDataNum))
renderFormattable(qualityData[[num()]])
But since some are not formattables, I want to check before doing the render. Instead of putting the tables in a list I created the following code to pick the table based on user input. It doesn't work, I get a warning: "Error in if: argument is of length zero".
num <- reactive(as.integer(input$qualityDataNum))
observe({
if (num() == 1) {
renderFormattable(qualityData1)
} else {
renderTable(qualityData2)
}
})
The complete code is below (since this is RMarkdown code it was reformated when
the three ticks were used for code marking. Sorry.):
title: "Dashboard Prototype"
output: flexdashboard::flex_dashboard
runtime: shiny
# allow sharing of dashboard
library(datasets)
library(flextable)
library(formattable)
library(dplyr)
options(stringsAsFactors = FALSE)
qData <- data.frame(Name = "AAA", Releases = 10, Coverage = 23.0)
qData <- bind_rows(qData, data.frame(Name = "BBB", Releases = 35, Coverage = 88.0))
#Using Formattable
data_formatter_dd <-
formattable::formatter("span", style = x ~ style( font.weight = "bold",
color = ifelse(x > 80.0 & x <= 100.0, "green", ifelse(x > 50.0 & x <= 80.0, "orange", "red"))))
qualityData1 <- formattable::formattable(qData, align = c("l", rep("r", ncol(qData) - 1)),
list('Name' = formattable::formatter("span", style = ~ style(color = "grey", font.weight = "bold")),
'Coverage' = data_formatter_dd))
#Using flextable
qualityData2 <- flextable(head(qData, col_keys = c("Name", "Releases", "Coverage")))
Sidebar {.sidebar}
# shiny inputs
selectInput("qualityDataNum", label = h3("Quality Number Set"), choice = list("1" = 1, "2" = 2),
selected = 1)
Quality Statistics
Quality
num <- reactive(as.integer(input$qualityDataNum))
observe({
req(num())
if (num() == 1) {
renderFormattable(qualityData1)
} else {
renderTable(qualityData2)
}
})
For Standalone Shiny Applications:
In order to achieve what you desire easily i would recommend to generate an output for each plottype and only populate it when the corresponding input is selected.
Down below you can find a complete example of this.
Generally speaking it is not advised to mix outputTypes (different render functions on the server side) into one output function (on the UI side)
# allow sharing of dashboard
library(datasets)
library(flextable)
library(formattable)
library(dplyr)
library(shiny)
options(stringsAsFactors = FALSE)
qData <- data.frame(Name = "AAA", Releases = 10, Coverage = 23.0)
qData <- bind_rows(qData, data.frame(Name = "BBB", Releases = 35, Coverage = 88.0))
data_formatter_dd <-
formattable::formatter("span", style = x ~ style( font.weight = "bold",
color = ifelse(x > 80.0 & x <= 100.0, "green", ifelse(x > 50.0 & x <= 80.0, "orange", "red"))))
qualityData1 <- formattable::formattable(qData, align = c("l", rep("r", ncol(qData) - 1)),
list('Name' = formattable::formatter("span", style = ~ style(color = "grey", font.weight = "bold")),
'Coverage' = data_formatter_dd))
qualityData2 <- flextable(head(qData, col_keys = c("Name", "Releases", "Coverage")))
ui <- fluidPage(
fluidRow(
selectInput("qualityDataNum", label = h3("Quality Number Set"), choice = list("1" = 1, "2" = 2),
selected = 1)
,
tableOutput("table2"),
formattableOutput("table1")
)
)
server <- function(input, output, session) {
output$table1 <- renderFormattable({
req(as.integer(input$qualityDataNum) == 1)
qualityData1
})
output$table2 <- renderTable({
req(as.integer(input$qualityDataNum) != 1)
qualityData2$body$dataset
})
}
shiny::shinyApp(ui,server)
EDIT:
For RMarkdown Code
I just rechecked your question and noticed that you were specifically asking how to handle the problem in an RMarkdown document and not in a standalone shiny Application. So here is an Update answer:
For RMarkdown it is enough that you update the code in your Quality Statistics section to the following:
renderFormattable({
req(as.integer(input$qualityDataNum) == 1)
qualityData1
})
renderTable({
req(as.integer(input$qualityDataNum) != 1)
qualityData2$body$dataset
})
Here you render the table according to the select input, it would be possible to render also multiple tables using this approach at the same time. This works since the req() functions checks if the requirement is fullfilled and only proceeds with the procession (aka the rendering of the plot) when it does. If it doesn't just an empty object is returned. Since we are using an reactive input inside the render function the expression get evaluate every time the Input value changes. If you do not want that consider wrapping it with an isolate() function, which tells the encapsulation function to not revaluate the function every time the encapsulate reactive Values/Inputs changes.

Resources