Observation data is not shown in the shiny application - r

I'm building a simple application in shiny to look at data divided to quadrants.
this is the server file:
shinyServer(function(input, output){
output$chart1 = renderChart({
library(rCharts)
data = data.frame(z = c("a","b","c","d","e","f","g","h","i","j"),y = sample(100,10),x = sample(100,10))
d1 = dPlot(
y ~ x,
groups = c("z"),
data =data,
type = "bubble"
)
d1$xAxis(type="addMeasureAxis",overrideMin = 0, overrideMax = 100)
d1$yAxis(type="addMeasureAxis",overrideMin = 0, overrideMax = 100)
medY = median(data$y)
medX = median(data$x)
d1$setTemplate(
afterScript = sprintf(
paste(
'
<script>
var line = d3.svg.line()
.x(function(d) { return myChart.axes[0]._draw.scale()(d.x); })
.y(function(d) { return myChart.axes[1]._draw.scale()(d.y); });
d3.select("#%s svg g")
.append("path")
.datum([{x:',medX,',y:0},{x:',medX,',y:100}])
.attr("d",line)
.style("stroke","red")
.style("stroke-width",1)
</script>
'
,sep = "")
,d1$params$dom
))
d1$layer(
y ~ x
,groups = c("x","y")
,data = data.frame(x = c(0,100), y = rep(medX,2))
,type="line"
,color='red'
)
d1$set(dom = 'chart1')
return(d1)
})
})
and here is the ui:
shinyUI(pageWithSidebar(
headerPanel("Test"),
sidebarPanel(),
mainPanel(showOutput("chart1", lib = "dimple"))
))
I get a chart but when I hover above the data points in the chart there is no description inside the boxes.
When I run the same code without the shiny application and look at the output at the viewer on RStudio i see the description.
I also added a vertical line which is not seen in the shiny application.
Anyone knows how to overcome this problem?
Thanks.

Related

I am having trouble multiple keywords separated by comma which can be used as a successful input in the function - does anyone have ideas?

This is UMAP function and by entering the colors names you can color the clusters but it is not working. It says that it sees only one color and 20 are needed. This is Seurat package.
This is the function that I used originally without shiny and it works
DimPlot(data, reduction = "umap", cols = c(colors[30], colors[1], colors[2], colors[28], colors[3],
colors[4], colors[5], "mistyrose", "lightpink4", colors[21], "grey", colors[7], colors[9], colors[11], colors[24], colors[26], "magenta" ,"gold", "mistyrose2"), split.by = "orig.ident")
This code below if from the shiny app I am making
server <- function(input, output) {
col = renderText({ input$label.color })
cols <- reactive({input$cols})
output$value <- renderText({ input$cols})
output$tsneplot<-renderPlot({
input$ts
if (input$spl == "NULL") {
isolate(DimPlot(data, seed = input$seed.use,reduction = "tsne",pt.size=input$pt.size, label = T, repel = T, label.size = input$label.size, cells = NULL, cols = NULL, label.color = "red"))
} else {
isolate(DimPlot(data, reduction = "tsne",pt.size= input$pt.size, split.by = input$spl ,cells = NULL, cols = c(cols()), label = T, label.size = input$label.size, label.color = col(), repel = T ))
}
})
}
I have seen the output value of text cols it shows exactly in the upper portion of the code below but for some reason while it is in the app and running the dimplot function it thinks it is only one string. Without the concept of shiny it works the code is tested but in the shiny platform it is not.
enter image description here
To examine what value cols() actually returns in your app, you can include a console-like output in your test version:
ui <- fluidPage(
## ...
verbatimTextOutput('log')
## ...
)
server <- function(input, output, session) {
## ...
output$log <- renderPrint(cols())
## ...
}

Function Not returning results on Shiny App

I wrote this function below:
leg.rpps = function(es, municipio) {
est = as.character(es)
mun = as.character(municipio)
url = paste0("https://apicadprev.economia.gov.br/RPPS_REGIME_PREVIDENCIARIO?sg_uf=",
est, "&no_ente=", curlEscape(mun), "&")
tmp = tempfile()
hdl = curl::new_handle(ssl_verifypeer = 0)
curl::curl_download(url, destfile = tmp, handle = hdl)
tpdt = fromJSON(tmp)
dt1 = (tpdt$results)
dt2 = dt1$data
dt.real = dt2[[1]]
rm(tpdt, tmp, dt1, dt2)
dados = cbind(dt.real$sg_uf, dt.real$no_ente, dt.real$no_tipo_legislacao,
dt.real$nr_legislacao, dt.real$dt_legislacao, dt.real$te_ementa)
colnames(dados) = c("UF", "Ente", "Tipo Legal", "No. Dispositivo",
"Data Publicação", "Ementa")
return(datatable(dados))
}
it works fine by itself, generating the expected results. But when I try to build a shiny app and call it , I get no results at all. The shiny page just stays blank where the data table was supposed to appear. Below is the code for my app (I must say that I'm a beginner on shiny, so I might be f'in up some shiny-related code)
library(shiny)
library(DT)
library(curl)
library(jsonlite)
library(RCurl)
ui <- fluidPage(
titlePanel("Legislação RPPS por Ente"),
sidebarLayout(
sidebarPanel(
textInput(inputId = "estado",
label = "Estado - Sigla:",
value = ""),
textInput(inputId = "municipio",
label = "Município:",
value = ""),
actionButton(
inputId = "click_go",
label = "Ir")
),
mainPanel(
h1("Legislação RPPS"),
h4("Utilizar sigla do Estado (Em maiúscula) e Nome do Município com as
iniciais em Maiúscula"),
dataTableOutput("tabela")
)
)
)
server <- function(input, output) {
leg.rpps = function(es, municipio){
url = paste0("https://apicadprev.economia.gov.br/RPPS_REGIME_PREVIDENCIARIO?sg_uf=",
es, "&no_ente=", curlEscape(municipio), "&")
tmp = tempfile()
hdl = curl::new_handle(ssl_verifypeer = 0)
curl::curl_download(url, destfile = tmp, handle = hdl)
tpdt = fromJSON(tmp)
dt1 = (tpdt$results)
dt2 = dt1$data
dt.real = dt2[[1]]
rm(tpdt, tmp, dt1, dt2)
dados = cbind(dt.real$sg_uf, dt.real$no_ente, dt.real$no_tipo_legislacao,
dt.real$nr_legislacao, dt.real$dt_legislacao, dt.real$te_ementa)
#colnames(dados) = c("UF", "Ente", "Tipo Legal", "No. Dispositivo",
# "Data Publicação", "Ementa")
#return(datatable(dados))
datatable(dados)
}
current_data = eventReactive(
input$click_go,
leg.rpps(input$estado, input$municipio)
)
output$tabela <- renderDataTable({
req(input$click_go)
current_data()
})
}
shinyApp(ui, server)
I'm having a really hard-time to figure out what might be wrong with this. If anyone can even point me out a way out of this, I will be very grateful.
Apparently, I was calling a datatable on another datatable.
when I changed datatable(dados) to dados on leg.rpps() outcome, it worked.

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

How can I make the color scale in mapdeck static

I am developing a shiny app which steps through time by each hour and shows the precipitation on a mapdeck map. I read in the weather data for the entire day and using reactivity filtering the data for the hour and plotting them as scatterplot using mapdeck_update to update the data. The color scale changes whenever the map updates based on the range of data in that hour. What I want is a static color scale based on the data range for the day. Is it possible?
I have tried using manual colors but for some reason they are not working
library(mapdeck)
ui <- fluidPage(
fluidRow(sliderInput(inputId = "hr",label = "Hour",min = 1,max = 3,value = 1)),
fluidRow(mapdeckOutput(outputId = "wx"))
)
sr <- function(input, output, session) {
mydata <- read.table(header=TRUE, sep=",",text="
ROW,COL,Center Latitude,Center Longitude,vil_int_36,hr
28,439,23.669885449218786,-97.2498101160108,20,1
41,433,24.37845221074034,-97.59803936272704,21,1
59,441,25.35333762373948,-97.11966878019186,22,1
61,441,25.461905262766468,-97.11878391116397,23,1
62,443,25.515163854569053,-96.99946877404128,24,1
29,439,23.724265738052193,-97.24945283742396,25,2
43,433,24.48713046908765,-97.59764743717052,26,2
59,442,25.35284441116698,-97.06032252207848,27,2
61,442,25.46141127997772,-97.05937801465758,28,2
62,444,25.514605007836384,-96.94003374232112,29,2
29,440,23.723846594719276,-97.19096992696834,30,3
43,434,24.486897474919978,-97.53876699838483,31,3
60,443,25.406603480942334,-97.00047511628769,32,3
62,441,25.516184831702166,-97.11834002241596,33,3
62,449,25.511327212479294,-96.64286546489153,34,3
")
wx_map <- mapdeck(data=NULL,token = Sys.getenv("MAPBOX_API_TOKEN"),style = 'mapbox://styles/mapbox/dark-v9',zoom = 6, location = c(-97,24.5))
observe({
wx_dt <- mydata %>% dplyr::filter(hr == input$hr)
mapdeck_update(map_id = "wx") %>%
add_scatterplot(data=wx_dt,lon = "Center.Longitude",lat = "Center.Latitude",radius = 15000,fill_colour = "vil_int_36",legend = TRUE,layer_id = "wxlyr",update_view = FALSE,focus_layer=FALSE)
})
output$wx <- renderMapdeck(wx_map)
}
shinyApp(ui, sr)
Notice how the range of color scale in the legend changes but the color of the dots stay almost the same. I want the color to represent the min-max of the entire data set (not just the hour) so that I can see change in intensity while stepping through each hour. Thank you.
Good question; you're right you need to create a manual legend so it remains static, otherwise it will update each time the values in the plot update.
The manual legend needs to use the same colours as the map. The map gets coloured by library(colourvalues). So you can use this to make the colours outside of the map, then use the results as the manual legend
l <- colourvalues::colour_values(
x = mydata$vil_int_36
, n_summaries = 5
)
legend <- mapdeck::legend_element(
variables = l$summary_values
, colours = l$summary_colours
, colour_type = "fill"
, variable_type = "category"
)
js_legend <- mapdeck::mapdeck_legend(legend)
Now this js_legend object is in the correct JSON format for the map to render it as a legend
js_legend
# {"fill_colour":{"colour":["#440154FF","#3B528BFF","#21908CFF","#5DC963FF","#FDE725FF"],"variable":["20.00","23.50","27.00","30.50","34.00"],"colourType":["fill_colour"],"type":["category"],"title":[""],"css":[""]}}
Here it is in your shiny
library(mapdeck)
library(shiny)
ui <- fluidPage(
fluidRow(sliderInput(inputId = "hr",label = "Hour",min = 1,max = 3,value = 1)),
fluidRow(mapdeckOutput(outputId = "wx"))
)
sr <- function(input, output, session) {
mydata <- read.table(header=TRUE, sep=",",text="
ROW,COL,Center Latitude,Center Longitude,vil_int_36,hr
28,439,23.669885449218786,-97.2498101160108,20,1
41,433,24.37845221074034,-97.59803936272704,21,1
59,441,25.35333762373948,-97.11966878019186,22,1
61,441,25.461905262766468,-97.11878391116397,23,1
62,443,25.515163854569053,-96.99946877404128,24,1
29,439,23.724265738052193,-97.24945283742396,25,2
43,433,24.48713046908765,-97.59764743717052,26,2
59,442,25.35284441116698,-97.06032252207848,27,2
61,442,25.46141127997772,-97.05937801465758,28,2
62,444,25.514605007836384,-96.94003374232112,29,2
29,440,23.723846594719276,-97.19096992696834,30,3
43,434,24.486897474919978,-97.53876699838483,31,3
60,443,25.406603480942334,-97.00047511628769,32,3
62,441,25.516184831702166,-97.11834002241596,33,3
62,449,25.511327212479294,-96.64286546489153,34,3
")
## create a manual legend
l <- colourvalues::colour_values(
x = mydata$vil_int_36
, n_summaries = 5
)
legend <- mapdeck::legend_element(
variables = l$summary_values
, colours = l$summary_colours
, colour_type = "fill"
, variable_type = "category"
)
js_legend <- mapdeck::mapdeck_legend(legend)
### --------------------------------
wx_map <- mapdeck(
style = 'mapbox://styles/mapbox/dark-v9'
, zoom = 6
, location = c(-97,24.5)
)
observe({
wx_dt <- mydata %>% dplyr::filter(hr == input$hr)
mapdeck_update(map_id = "wx") %>%
add_scatterplot(
data = wx_dt
, lon = "Center.Longitude"
, lat = "Center.Latitude"
, radius = 15000
, fill_colour = "vil_int_36"
, legend = js_legend
, layer_id = "wxlyr"
, update_view = FALSE
, focus_layer = FALSE
)
})
output$wx <- renderMapdeck(wx_map)
}
shinyApp(ui, sr)

multiple selection in checkboxGroupInput and plotting in shiny

In my shiny app I have a checkboxGroupInput
How should I do the plot command in server function, in a way that I plot the TurbInt_mean against MeanWindSpeed_mean and add lines (curves) to the plot by user selection ?
I have tried to summaries my shiny app as reproduce-able code as follow (you have to first load the sample data that I have provided)
library(shiny)
ui <- fluidPage(
checkboxGroupInput("variable", "Select IEC Classes for TI",c("A Plus" = "ap","A" = "a","B" = "b","C"="c")),
plotOutput("plotmeanTI",width = "100%") )
server <- function(input, output, session){
output$plotmeanTI <- renderPlot({
plot(as.matrix(TI_plot[,1]),as.matrix(TI_plot[,2]),t='o',ylim=c(0,1),xaxs="i",
xlab="Mean Wind Speed", ylab="<TI>")
if(input$variable=="ap"){lines(as.matrix(TI_plot[,1]),TI_plot$NTM_A_Plus_mean,col=6)}
if(input$variable=="a"){lines(as.matrix(TI_plot[,1]),TI_plot$NTM_A_mean,col=2)}
if(input$variable=="b"){lines(as.matrix(TI_plot[,1]),TI_plot$NTM_B_mean,col=3)}
if(input$variable=="c"){lines(as.matrix(TI_plot[,1]),TI_plot$NTM_C_mean,col=4)}
})
}
shinyApp(ui=ui,server=server)
If user select 1, one curve should be added, if select more than one, I want to have multiple curves added to my plot.I can do it for single selection like I have explained in my code, but when I have multi selection it does not work.
My data set looks like :
dput(TI_plot)
structure(list(MeanWindSpeed_mean = c(0.292023070097604, 1.12011882699226,
2.0283906614786, 3.00947886508396, 4.01428066037736, 5.01250749719984,
6.0080377166157, 7.00777409860191, 8.0049941822883, 9.00201938353988,
9.99646762244478, 10.9883558855227, 11.9798700705476, 12.976996101646,
13.9653724394786, 14.9495068163593, 15.9628459343795, 16.9708685581934,
17.9623943661972, 18.992621231979, 19.9643220338983, 20.9834693877551,
22.0170278637771, 22.9658904109589, 24.0025266903915, 24.9935025380711
), TurbInt_mean = c(3.02705430346051, 0.420402191213343, 0.264195029831388,
0.215109260166585, 0.18794121258946, 0.16699392997796, 0.148261539245668,
0.134479958525654, 0.122038442146089, 0.110595865904036, 0.097103704211826,
0.0836329541372291, 0.0708397249149876, 0.0622491842333237, 0.0591184473929236,
0.0611678829190056, 0.0652080242510699, 0.0690131441806601, 0.073762588028169,
0.0756961992136304, 0.0805696610169492, 0.0817446428571429, 0.0830263157894737,
0.0827277397260274, 0.0749537366548043, 0.0765532994923858),
NTM_A_Plus_mean = c(Inf, 1.10260388189292, 0.642329939163608,
0.473065816856713, 0.387417559923049, 0.336769624752903,
0.303163441845455, 0.27908457313955, 0.261084722917897, 0.247090026094941,
0.235918715179959, 0.226796351934008, 0.219190019655214,
0.212713243118379, 0.20720881268079, 0.202452008587075, 0.19816685602934,
0.19441329542209, 0.191131377464549, 0.188086340606011, 0.185500707351721,
0.18304730715887, 0.180790073836667, 0.178898058874634, 0.177002145398197,
0.175335040729601), NTM_A_mean = c(Inf, 0.98009233946037,
0.570959945923208, 0.420502948317078, 0.344371164376044,
0.299350777558136, 0.269478614973738, 0.248075176124045,
0.232075309260353, 0.219635578751059, 0.209705524604408,
0.201596757274674, 0.194835573026857, 0.189078438327448,
0.184185611271814, 0.179957340966289, 0.176148316470525,
0.172811818152969, 0.169894557746266, 0.167187858316455,
0.164889517645975, 0.162708717474551, 0.160702287854815,
0.159020496777452, 0.157335240353953, 0.155853369537423),
NTM_B_mean = c(Inf, 0.857580797027824, 0.499589952682807,
0.367940079777444, 0.301324768829038, 0.261931930363369,
0.23579378810202, 0.217065779108539, 0.203065895602809, 0.192181131407176,
0.183492334028857, 0.176397162615339, 0.1704811263985, 0.165443633536517,
0.161162409862837, 0.157462673345503, 0.154129776911709,
0.151210340883848, 0.148657738027983, 0.146289376026898,
0.144278327940228, 0.142370127790232, 0.140614501872963,
0.139142934680271, 0.137668335309708, 0.136371698345246),
NTM_C_mean = c(Inf, 0.735069254595278, 0.428219959442406,
0.315377211237809, 0.258278373282033, 0.224513083168602,
0.202108961230303, 0.186056382093034, 0.174056481945265,
0.164726684063294, 0.157279143453306, 0.151197567956005,
0.146126679770143, 0.141808828745586, 0.13813920845386, 0.134968005724717,
0.132111237352894, 0.129608863614727, 0.127420918309699,
0.125390893737341, 0.123667138234481, 0.122031538105913,
0.120526715891111, 0.119265372583089, 0.118001430265464,
0.116890027153068)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -26L), .Names = c("MeanWindSpeed_mean",
"TurbInt_mean", "NTM_A_Plus_mean", "NTM_A_mean", "NTM_B_mean",
"NTM_C_mean"))
the head of TI_plot is like :
head(TI_plot)
# A tibble: 6 x 6
MeanWindSpeed_mean TurbInt_mean NTM_A_Plus_mean NTM_A_mean NTM_B_mean NTM_C_mean
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 0.2920231 3.0270543 Inf Inf Inf Inf
2 1.1201188 0.4204022 1.1026039 0.9800923 0.8575808 0.7350693
3 2.0283907 0.2641950 0.6423299 0.5709599 0.4995900 0.4282200
4 3.0094789 0.2151093 0.4730658 0.4205029 0.3679401 0.3153772
5 4.0142807 0.1879412 0.3874176 0.3443712 0.3013248 0.2582784
6 5.0125075 0.1669939 0.3367696 0.2993508 0.2619319 0.2245131
We could use switch
library(shiny)
ui <- fluidPage(
checkboxGroupInput("variable", "Select IEC Classes for TI",c("A Plus" = "ap","A" = "a","B" = "b","C"="c"),
selected = c("A Plus" = "ap")),
plotOutput("plotmeanTI",width = "100%")
)
server <- function(input, output, session){
output$plotmeanTI <- renderPlot({
f1 <- function(nm1){
switch(nm1,
ap = lines(TI_plot[[1]],TI_plot$NTM_A_Plus_mean,col=6),
a = lines(TI_plot[[1]],TI_plot$NTM_A_mean,col=2),
b = lines(TI_plot[[1]],TI_plot$NTM_B_mean,col=3),
c = lines(TI_plot[[1]],TI_plot$NTM_C_mean,col=4)
)
}
if(is.null(input$variable)) {
plot(TI_plot[[1]], TI_plot[[2]],t='o',ylim=c(0,1),xaxs="i",
xlab="Mean Wind Speed", ylab="<TI>")
} else {
plot(TI_plot[[1]], TI_plot[[2]],t='o',ylim=c(0,1),xaxs="i",
xlab="Mean Wind Speed", ylab="<TI>")
f1(input$variable)
}
})
}
shinyApp(ui=ui,server=server)
-output
Using ggplot2
library(shiny)
library(ggplot2)
library(tidyr)
library(dplyr)
ui <- fluidPage(
checkboxGroupInput("variable", "Select IEC Classes for TI",c("A Plus" = "ap","A" = "a","B" = "b","C"="c"),
selected = c("A Plus" = "ap")),
plotOutput("plotmeanTI",width = "100%") )
server <- function(input, output, session){
output$plotmeanTI <- renderPlot({
keyvaldata <- data.frame(key = c('NTM_A_Plus_mean', 'NTM_A_mean', 'NTM_B_mean', 'NTM_C_mean' ),
Var = c('ap', 'a', 'b', 'c'), stringsAsFactors = FALSE)
p1 <- gather(TI_plot, key, val, -MeanWindSpeed_mean, -TurbInt_mean) %>%
left_join(., keyvaldata) %>%
filter(Var %in% input$variable) %>%
ggplot(., aes(MeanWindSpeed_mean, TurbInt_mean, colour = Var)) +
geom_line() +
geom_line(aes(y =val)) +
labs(x = "Mean Wind Speed", y = "<TI>") +
theme_bw()
if(is.null(input$variable)) {
ggplot(TI_plot, aes(MeanWindSpeed_mean, TurbInt_mean)) +
geom_line() +
labs(x = "Mean Wind Speed", y = "<TI>") +
theme_bw()
} else {
p1
}
})
}
shinyApp(ui=ui,server=server)
-output

Resources