ggplot2 isn't recognizing shiny's reactive data - r
everyone!
I'm trying hard here to get the data I grouped by the 'fc' function and it was supposed to be in this new dataset 'reac', where I wanted it to be updated when a user input which variable he/she wants to use at shiny's UI (input$x, input$y, input$color). Then I want to use this new reac dataset in ggplot, but the 'aes_string() isn't working, the compiler doesn't recognize the data type as a dataframe and I'm getting a "Can't convert NULL to a quosure" error and "Unknown input:tbl_df" error.
Sorry for the bad english, it isn't my mothertongue! :(
Thanks in advance!
PS: Link for the code
library(shiny)
library(plotly)
library(rsconnect)
library(sidrar)
library(dplyr)
library(ggplot2)
#dados261<-get_sidra(api="/t/261/n2/all/n3/all/v/allxp/p/last%2011/c1/allxt/c2/allxt/c58/1140,1141,1142,1143,1144,1145,1146,1147,1148,1149,1150,1151,1152,1153,2792,2793,3244,3245/d/v93%203")
load("C:/Users/Fausto/Desktop/dados_1.RData")
colnames(dados261)<-c("nt_cod","nt","regiao_cod","regiao","va_cod","va","ano_cod","ano","dom_cod","dom","sexo_cod","sexo","id_cod","id","um_cod","um","valor")
names1 <- c("nt_cod","regiao_cod","va_cod","ano_cod","dom_cod","sexo_cod","id_cod","um_cod")
dados261[names1] <- sapply(dados261[names1],as.numeric)
years<-as.numeric(sort(unique(dados261$ano)))
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
h1("Tabela 261 - SIDRA - Dados Gerais"),
selectInput("x", label = "Eixo x", choices = list("Região" = "regiao", "Idade" = "id", "Sexo" = "sexo", "DomicÃlio" = "dom", "Valores" = "valor"), selected = "regiao"),
selectInput("y", label = "Eixo Y", choices = list("Região" = "regiao", "Idade" = "id", "Sexo" = "sexo", "DomicÃlio" = "dom", "Valores" = "valor"), selected = "valor")
),
mainPanel(
tabsetPanel(
tabPanel("Gráfico de barras",
plotOutput("plot", width = "80%", height = "80%"),
radioButtons("color", label = "Preenchimento", choices = list("Região" = "regiao", "Idade" = "id", "Sexo" = "sexo", "DomicÃlio" = "dom", "Nenhuma" = "id"), selected = "nn", inline = TRUE)),
tabPanel("Série Temporal",
plotOutput("plot2", width = "100%", height = "100%"),
sliderInput("ano", label = "Anos", min = min(years), max= max(years), value=c(min(years),max(years)))
)
)
)
)
)
server <- function(input, output){
fc<- function(data, ...) {
data %>% group_by_(...) %>%
summarise(valor2 = sum(valor, na.rm = TRUE)) -> data
return(data)
}
reac<-reactive({
fc(dados261, input$x, input$y, input$color)
})
output$plot <- renderPlot({
eixox<-as.character(reac()[,1])
eixoy<-as.numeric(reac()$valor2)
eixoz<-as.character(reac()[,2])
p<- reac() %>%
ggplot() +
aes_q(eixox, eixoy, fill= eixoz) +
geom_bar(stat = "identity")
ggplotly(p)
}, height = 600, width = 900)
}
shinyApp(ui = ui, server = server)
When I loaded your .Rdata, and ran the code with changes suggested by Alejandro, my graphs changed.
loaded the libraries excluding sidrar and rsconnect, and ran the code:
library(shiny)
library(plotly)
library(dplyr)
library(ggplot2)
load("/Users/username/Downloads/RData.RData")
#Renomeando as colunas
colnames(dados261)<-c("nt_cod","nt","regiao_cod","regiao","va_cod","va","ano_cod","ano","dom_cod","dom","sexo_cod","sexo","id_cod","id","um_cod","um","valor")
#transformando as variáveis que estao como "char" em "integer"
names1 <- c("nt_cod","regiao_cod","va_cod","ano_cod","dom_cod","sexo_cod","id_cod","um_cod")
dados261[names1] <- sapply(dados261[names1],as.numeric)
years<-as.numeric(sort(unique(dados261$ano)))
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
h1("Tabela 261 - SIDRA - Dados Gerais"),
selectInput("x", label = "Eixo x", choices = list("Regiao" = "regiao", "Idade" = "id", "Sexo" = "sexo", "Domicilio" = "dom", "Valores" = "valor"), selected = "regiao"),
selectInput("y", label = "Eixo Y", choices = list("Regiao" = "regiao", "Idade" = "id", "Sexo" = "sexo", "Domicilio" = "dom", "Valores" = "valor"), selected = "valor")
),
mainPanel(
tabsetPanel(
tabPanel("Grafico de barras",
plotOutput("plot", width = "80%", height = "80%"),
radioButtons("color", label = "Preenchimento", choices = list("Regiao" = "regiao", "Idade" = "id", "Sexo" = "sexo", "Domicilio" = "dom"), selected = "id", inline = TRUE)),
tabPanel("Serie Temporal",
plotOutput("plot2", width = "100%", height = "100%"),
sliderInput("ano", label = "Anos", min = min(years), max= max(years), value=c(min(years),max(years)))
)
)
)
)
)
server <- function(input, output){
fc<- function(data, ...) {
data %>% group_by_(...) %>%
summarise(valor2 = sum(valor, na.rm = TRUE)) -> data
return(data)
}
reac<-reactive({
fc(dados261, input$x, input$y, input$color)
})
output$plot <- renderPlot({
eixox<-as.character(reac()[,1])
eixoy<-as.numeric(reac()$valor2)
eixoz<-as.character(reac()[,3])
reac() %>%
ggplot() +
aes_string(eixox, eixoy, fill= eixoz) +
geom_bar(stat = "identity")
}, height = 600, width = 900)
}
shinyApp(ui,server)
Related
How do I add the option to connect observations by ID in Shiny?
I'm working on my Shiny app that visualizes/summarizes PK data. Anyways, I have a small question. I want to add in the option for the user to connect observations by ID in Shiny, so I want them to choose. This could be a single tickbox which would be: "Connect observations by ID', or just a statement like: 'Connect observations by ID:" with boxes as 'Yes' or 'No'. I hope you get what I mean. How do I do this? I have a pretty large code for my app, as I've come a long way already. Small note, I can't generate a report yet, as the code is not right, but you can just ignore this. Tab 2 is not finished yet, but the base is there. UI ui <- fluidPage( tabsetPanel(tabPanel("Tab 1", titlePanel("Shiny App: Concentration vs Time Graphs"), sidebarLayout( mainPanel("Concentration vs Time graphs", plotOutput(outputId = "plot")), sidebarPanel(style = "height:90vh; overflow-y: auto", p("This app is developed to visualize pharmacokinetic data of different antibodies. Please select the data you want to visualize before running the graph. The graph can be reset with the reset button."), strong("1. Filter your data for these following variables:"), checkboxInput('checkbox1', 'Filter by study', FALSE), conditionalPanel(condition = "input.checkbox1 == 1", selectInput(inputId = "study", label = "Include study:", choices = c("GLP Toxicity" = "GLPTOX", "Dose Range Finding" = "DRF", "Single Dose" = "SD", "Repeat Dose" = "RD"), selected = c("GLPTOX", "DRF", "SD", "RD"), multiple = T) ), checkboxInput('checkbox2', 'Filter by platform', FALSE), conditionalPanel(condition = "input.checkbox2 == 1", selectInput(inputId = "platform", label = "Include platform:", choices = c("Hexabody", 'Duobody' = "Doubody", "Bispecific"), selected = c("Hexabody", "Doubody", "Bispecific"), multiple = T) ), checkboxInput('checkbox3', 'Filter by species', F), conditionalPanel(condition = "input.checkbox3 == 1", selectInput(inputId = "species", label = "Include species:", choices = c("Monkey", 'Mouse'), selected = c('Monkey', 'Mouse'), multiple = T) ), checkboxInput('checkbox4', 'Filter by administration route', F), conditionalPanel(condition = "input.checkbox4 == 1", selectInput(inputId = "route", label = "Include administration route:", choices = c('Route 1' = "ROUTE1", 'Route 2' = "ROUTE2"), selected = c("ROUTE1", "ROUTE2"), multiple = T) ), selectInput(inputId = "x", label = "2. X-axis:", choices = c("Time" = "TIME", "TLD"), selected = "Time" ), selectInput(inputId = 'column', label = "3. Columns for:", choices = c("Dose mg/kg" = "DOSEMGKG", "Species" = "SPECIES", "Antibody" = "ABXID", "Subspecies" = "SUBSPECIES", "Age" = "AGE", "Animal ID" = "ANIMALID"), selected = "DOSEMGKG" ), conditionalPanel(condition = "input.column == 'DOSEMGKG'", selectInput(inputId = 'dose', label = "Choose dose(s):", choices = c("0.05", '0.5', "20", '5'), selected = c('0.05', '0.5', '20', '5'), multiple = T ) ), selectInput(inputId = 'row', label = "4. Rows for:", choices = c("Dose mg/kg" = "DOSEMGKG", "Species" = "SPECIES", "Antibody" = "ABXID", "Subspecies" = "SUBSPECIES", "Age" = "AGE", "Animal ID" = "ANIMALID", "Platform" = "PLATFORM", "Mutation" = "MUTATION"), selected = "ABXID" ), conditionalPanel(condition = "input.row == 'MUTATION'", selectInput(inputId = 'mutation', label = "Choose mutation(s):", choices = c('M1', "M2", "M3"), selected = c('M1', "M2", "M3"), multiple = T ) ), conditionalPanel( condition = "input.row == 'ABXID'", selectInput( inputId = 'antibody', label = "Choose antibody(s):", choices = c('Duobody-XXXXX', "Duobody-CD3x5T4"), selected = c('Duobody-XXXXX', 'Duobody-CD3x5T4'), multiple = T ) ), selectInput( inputId = "group", label = "5. Group by:", choices = c("Dose mg/kg" = "DOSEMGKG", "Species" = "SPECIES", "Antibody" = "ABXID", "Subspecies" = "SUBSPECIES", "Age" = "AGE", "Animal ID" = "ANIMALID", 'Administration route' = 'ROUTE'), selected = "ANIMALID" ), sliderInput( inputId = 'trange', label = "6. Time range:", min = 0, max = 1704, value = c(0, 1704 ) ), actionButton( inputId = 'runbutton', label = 'Run graph' ), actionButton( inputId = 'resetbutton', label = 'Reset graph' ), downloadButton(outputId = 'report', label = "Generate report"), br(), br(), br(), p("----------") )) )), tabsetPanel(tabPanel("Tab 2", titlePanel("Tab 2"), sidebarLayout( mainPanel("Plot #2", plotOutput(outputId = "plot2")), sidebarPanel(helpText("Whatever text..."), selectInput( inputId = 't', label = "Example", choices = c("#1", "#2", "#3"), selected = "#1" ) ) ))) ) Server server <- function(input, output, session){ observeEvent(input$runbutton, {output$plot <- renderPlot({ ggplot(data = df %>% filter(STUDYID %in% input$study & ABXID %in% input$antibody & MUTATION %in% input$mutation & PLATFORM %in% input$platform & SPECIES %in% input$species & DOSEMGKG %in% input$dose & ROUTE %in% input$route), aes_string(x = input$x, y = "DV", col = input$group)) + xlab("Time") + ylab("Concentration (ug/mL)") + geom_point() + facet_grid(get(input$row) ~ get(input$column)) + scale_x_continuous(limits = input$trange) + scale_color_viridis(discrete = T, option = 'F', begin = 0, end = 0.8) + theme_bw() + scale_y_log10()})}) observeEvent(input$resetbutton, {output$plot <- renderPlot({ NULL })}) output$report <- downloadHandler(filename = "report.pdf", content = function(file){ tempReport <- file.path(tempdir(), "report.Rmd") file.copy("report.Rmd", tempReport, overwrite = T) params <- list(n = input$x) rmarkdown::render(tempReport, output_file = file, params = params, envir = new.env(parent = globalenv())) }) } shinyApp(ui = ui, server = server) I know that it's something with geom_line(aes(group = "ANIMALID")), but I do not yet know how to make this an option to include/exclude.
Here is a simple app, that has a ggplot2 with some data, and whether the points are to be drawn connected by lines (within relevant groups) is toggleable. I hope it helps you; your posted code is not reproducible as it uses private data, (and it is not minimal, its a lot of content to look at). perhaps you can use this example as a base to ask further questions from as you complicate it, or account for relevant differences. but notice how my example is at least reproducible (you can run it; it is based on public, not private data). library(shiny) library(tidyverse) some_data <- distinct( iris, Species, Petal.Width, Petal.Length ) |> group_by(Species, Petal.Width) |> summarise(avg_Petal.Length = mean(Petal.Length)) |> ungroup() ui <- fluidPage( plotOutput("myplot", width = 400, height = 400), checkboxInput("mytog", "line?") ) server <- function(input, output, session) { output$myplot <- renderPlot({ plot_to_show <- ggplot(data = some_data) + aes( x = Petal.Width, y = avg_Petal.Length, colour = Species ) + geom_point() if (isTruthy(input$mytog)) { plot_to_show <- plot_to_show + geom_line() } plot_to_show }) } shinyApp(ui, server)
Create graph based on selection of input and output
New to shiny. I am trying to create a plot based on chosen x and y values. Basically, whatever the user selects for the select1 and select2 selectInput function will graph it accordingly. My original data has many columns, not just two. When I try to graph very specific things, my code works great, but when I try to graph what the user "selects" it does not work. library(shiny) library(readr) library(ggplot2) library(dplyr) data0 <- rnorm(n = 10, mean = 100, sd = 5) data1 <- rnorm(n = 10, mean = 50, sd = 10) data2 <- data.frame(data0, data1) attach(data2) ui <- fluidPage( selectInput(inputId = "select1", label = "select the x-axis", choices = c(" ", "data0", "data1") ), selectInput(inputId = "select2", label = "select the y-axis", choices = c(" ", "data0", "data1") ), submitButton(text = "Apply Changes", icon = NULL, width = NULL), plotOutput(outputId = "myplot") ) server <- function(input, output) { output$myplot <- renderPlot({ data2 %>% ggplot(aes(input$select1 ~ input$select2))+ geom_point(alpha = 0.8) }) } shinyApp(ui = ui, server = server)
I had to add ggplot(aes(x = get(paste(input$select1)), y = get(paste(input$select2)) to make the input selects work. library(shiny) library(readr) library(ggplot2) library(dplyr) data0 <- read_csv("DeltaX_Soil_Properties_Fall2020_Spring2021_Fall2021.csv") data1 <- data0[!(data0$time_marker_sampled == "-9999"),] attach(data1) ui <- fluidPage( selectInput(inputId = "select1", label = "select the x-axis", choices = c(" ", "elevation_navd88", "sediment_accretion", "days_between_sampling_and_deployment", "normalized_accretion", "soil_bulk_density", "soil_organic_matter_content", "soil_organic_carbon", "soil_organic_carbon_density") ), selectInput(inputId = "select2", label = "select the y-axis", choices = c(" ", "elevation_navd88", "sediment_accretion", "days_between_sampling_and_deployment", "normalized_accretion", "soil_bulk_density", "soil_organic_matter_content", "soil_organic_carbon", "soil_organic_carbon_density") ), submitButton(text = "Apply Changes", icon = NULL, width = NULL), plotOutput(outputId = "myplot") ) server <- function(input, output) { output$myplot <- renderPlot({ data1 %>% ggplot(aes(x = get(paste(input$select1)), y = get(paste(input$select2)), col = hydrogeomorphic_zone))+ geom_point(alpha = 0.8) }) } shinyApp(ui = ui, server = server)
If you want to use a variable as x or y, you can alternatively use aes_() instead of aes(). This would then result in: ggplot(aes_(x = input$select1, y = input$select2)) Beware, that you need to add a tilde if you want to use a normal column name with aes_(), e.g.: ggplot(aes_(x = ~elevation_navd88, y = input$select2))
Problem with Shiny and Plotly. Error in UseMethod
I am trying to render plotly based on the input selection. I am receiving an error: Warning: Error in UseMethod: no applicable method for 'layout' applied to an object of class "shiny.tag". library(dplyr) library(ggplot2) library(shiny) library(shinydashboard) library(ggplot2) library(plotly) library(plotDK) df <- tibble(postnr = c(4000, 2000,9000), kommunekoder = c(101, 147,153), reg_code = c(1,2,3), count = c(3,5,6)) ui <- shinyUI(fluidPage( box(plotlyOutput("map")), box(selectInput( "level", label= "Select map level:", choices = c("Zip code", "Municipality", "Region"), multiple = FALSE, selected = "Zip code"), solidHeader = TRUE, width = "5", height = "75px", status = "primary" ))) server <- shinyServer(function(input, output) { plot <- reactive({ifelse(input$level == "Zip code", plotDK(plotlevel = "zipcode", value = "count", id ="postnr" , data = df, show_missing = TRUE), ifelse(input$level == "Municipality", plotDK(plotlevel = "municipality", value = "count", id ="kommunekoder" , data = df, show_missing = TRUE), plotDK(plotlevel = "region", value = "count", id ="reg_code" , data = df, show_missing = TRUE)))}) output$map <- renderPlotly({ggplotly(plot() + scale_fill_continuous(name ="Number of firms")) %>% layout(height = 500, width = 650) }) }) shinyApp(ui = ui, server) If I run the code in outside Shiny, it works: plot <- plotDK(plotlevel = "region", value = "count", id ="reg_code" , data = df, show_missing = TRUE) ggplotly(plot + scale_fill_continuous(name ="Number of firms")) %>% layout(height = 500, width = 650) What am I missing?
Would it be possible to change your Server function to: server <- shinyServer(function(input, output) { output$map <- renderPlotly({ if(input$level == "Zip code"){ p <- plotDK(plotlevel = "zipcode", value = "count", id ="postnr" , data = df, show_missing = TRUE) } if(input$level == "Municipality"){ p <- plotDK(plotlevel = "municipality", value = "count", id ="kommunekoder" , data = df, show_missing = TRUE) } if(input$level == "Region"){ p <- plotDK(plotlevel = "region", value = "count", id ="reg_code" , data = df, show_missing = TRUE) } ggplotly(p + scale_fill_continuous(name ="Number of firms")) %>% layout(height = 500, width = 650) }) }) This embeds the plotting function inside the map output. If you really need the plot to be stored in a reactive, then this won't work, but if you just need to make the plot so it can be rendered in the output, this should do the trick.
How to create an action button that delete the last input/row (enterer by clicking), but being able to keep entering data in R shiny
I am trying to insert an action button that would delete the last input/row of data (enterer by clicking), but I want to be able to keep entering data by clicking afterward. I summary I have a dataframe which is accumulating data every time I click on the plot, I want an action button that remove the last click and data that goes with it in the dataframe, but I want to be able to keep going afterward. I try a simple solution because I feel it should be simple, but I cannot get it. Thank you very much for your help. library(shiny) library(ggplot2) ui <- fluidPage( titlePanel("team"), sidebarPanel( textInput(inputId = "date", label = "Date", value = "yyyy/mm/dd"), textInput(inputId = "team", label = "Team Name", value = "Team Name"), textInput(inputId = "pnumber", label = "Player Number", value = "#"), selectInput("shot", "shot type:", list(`Shot Type` = list("wrist shot", "slap shot", "snap shot"))), selectInput("situation", "scoring opportunity:", list(`Green` = list("Double cross", "dot line pass"), `Red` = list("clear", "wrap"))), actionButton("reset", "Clear")), mainPanel(tabsetPanel( tabPanel("Track", plotOutput(outputId = "hockeyplot", click = "plot_click", dblclick = "plot_dblclick")), tabPanel("Data", tableOutput(outputId = "table"), downloadLink("downloadData", "Download")), tabPanel("Chart", plotOutput(outputId = "chart"))))) server <- function(input, output){ rv <- reactiveValues( df = data.frame( x = numeric(), y = numeric(), Date = as.Date(character()), Team = character(), Player = character(), ShotType = character(), Situation = character(), Type = factor() ) ) output$hockeyplot = renderPlot({ ggplot(rv$df, aes(x = x, y = y)) + coord_flip() + lims(x = c(0, 100), y = c(42.5, -42.5))+ geom_point( aes(colour = factor(Type)), size = 5 ) + theme(legend.position = "none")}) observeEvent(input$plot_click, { rv$df <- rbind(rv$df, data.frame( x = input$plot_click$y, y = input$plot_click$x, Date = input$date, Team = input$team, Player = input$pnumber, ShotType = input$shot, Situation = input$situation, Type = "Shot")) }) observeEvent(input$plot_dblclick, { rv$df <- rbind(rv$df, data.frame( x = input$plot_dblclick$y, y = input$plot_dblclick$x, Date = input$date, Team = input$team, Player = input$pnumber, ShotType = input$shot, Situation = input$situation, Type = "Goal")) }) observeEvent(input$reset,{ rv$df( rv$df()[-nrow(rv$df()),]) }) output$table<-renderTable({ rv$df }) output$downloadData <- downloadHandler( filename = function() { paste("MHdata-", Sys.Date(), ".csv", sep="") }, content = function(file) { write.csv(rv$df, file) } ) } shinyApp(ui = ui, server = server)
You mixed up some brackets when using reactiveValues. Basically, you can call and assign them without (. library(shiny) library(ggplot2) ui <- fluidPage( titlePanel("team"), sidebarPanel( textInput(inputId = "date", label = "Date", value = "yyyy/mm/dd"), textInput(inputId = "team", label = "Team Name", value = "Team Name"), textInput(inputId = "pnumber", label = "Player Number", value = "#"), selectInput("shot", "shot type:", list(`Shot Type` = list("wrist shot", "slap shot", "snap shot"))), selectInput("situation", "scoring opportunity:", list(`Green` = list("Double cross", "dot line pass"), `Red` = list("clear", "wrap"))), actionButton("reset", "Clear")), mainPanel(tabsetPanel( tabPanel("Track", plotOutput(outputId = "hockeyplot", click = "plot_click", dblclick = "plot_dblclick")), tabPanel("Data", tableOutput(outputId = "table"), downloadLink("downloadData", "Download")), tabPanel("Chart", plotOutput(outputId = "chart"))))) server <- function(input, output){ rv <- reactiveValues( df = data.frame( x = numeric(), y = numeric(), Date = as.Date(character()), Team = character(), Player = character(), ShotType = character(), Situation = character(), Type = factor() ) ) output$hockeyplot = renderPlot({ ggplot(rv$df, aes(x = x, y = y)) + coord_flip() + lims(x = c(0, 100), y = c(42.5, -42.5))+ geom_point( aes(colour = factor(Type)), size = 5 ) + theme(legend.position = "none")}) observeEvent(input$plot_click, { rv$df <- rbind(rv$df, data.frame( x = input$plot_click$y, y = input$plot_click$x, Date = input$date, Team = input$team, Player = input$pnumber, ShotType = input$shot, Situation = input$situation, Type = "Shot")) }) observeEvent(input$plot_dblclick, { rv$df <- rbind(rv$df, data.frame( x = input$plot_dblclick$y, y = input$plot_dblclick$x, Date = input$date, Team = input$team, Player = input$pnumber, ShotType = input$shot, Situation = input$situation, Type = "Goal")) }) # NO BRACKETS NEEDED observeEvent(input$reset,{ rv$df <- rv$df[-nrow(rv$df),] }) output$table<-renderTable({ rv$df }) output$downloadData <- downloadHandler( filename = function() { paste("MHdata-", Sys.Date(), ".csv", sep="") }, content = function(file) { write.csv(rv$df, file) } ) } shinyApp(ui = ui, server = server)
Plot not rendering on starting an app when combined with leaflet map
I have a problem with this Shiny app: Minimum working example The shiny app that has the following structure (full code pasted below): ui <- fluidPage( fluidRow( column(6, plotOutput("plot_main", click = "plot_click",height = 800)), column(6, leafletOutput("Map_Clicked",height = 800)) ), fluidRow(...)) The "plot_main" is generated using ggplot2 and "Map_Clicked" is generated using leaflet. Everything works well except that the "plot_main" is not rendered unless I change some input to it. For example, if I even change the size of the browser window, the plot is rendered. Even if i restore it to the original size, it is again rendered and everything works well. Also, if I display the plot without the map, it is rendered okay. It is only when I keep them in the same fluid row does it not render at start up. Has anyone else experienced this before? Thanks. Update (Working Example): library(tidyverse) library(shiny) library(leaflet) set.seed(5) Ramps_Summary = read.csv(text = '"LINK_ID","FC","UNTLD1","SC","UNTLD2","UNTLD3","UNTLD4","UNTLD5","UNTLD6","UNTLD7","UNTLD8","UNTLD9","UNTLD10","SIZE","NET_ANGLE_CHANGE","MAX_ANGLE_CHANGE","SUM_ANGLE_CHANGE","All","LENGTH" 1,7,1,3,6,1,7,8,0,7,9,1,3,8,7,1,9,"All",1 2,7,1,6,8,2,5,5,6,8,8,3,3,7,8,8,1,"All",3 3,3,3,6,7,5,3,5,10,10,10,6,1,8,2,3,5,"All",4 4,7,5,2,7,10,7,2,4,1,6,2,2,7,9,4,6,"All",8 5,7,3,7,3,9,5,1,6,3,7,6,6,9,5,9,2,"All",4 6,4,1,6,6,5,4,7,9,8,1,5,6,2,3,0,6,"All",1 7,9,1,6,2,4,7,9,2,10,5,8,2,5,5,6,9,"All",10 8,8,8,6,4,7,7,9,3,4,8,7,6,8,1,2,8,"All",5 9,6,3,6,2,3,3,2,7,7,9,1,7,9,5,4,6,"All",6 10,0,7,3,0,5,4,1,3,6,6,1,1,8,7,0,6,"All",8') Ramps_Geom = read.csv(text = '"LINK_ID","SEQ_NUM","LAT","LON","SEG_LEN_M","SEG_BEARING_F","SEG_BEARING_CHANGE_F","SEG_BEARING_T" 8,2,40.7584690905452,-73.9854012361834,5,9,6,2 8,9,40.7580278345045,-73.9845919920848,1,4,9,3 8,10,40.7592006631164,-73.9858852190994,0,7,9,1 8,0,40.7586196884458,-73.9844548667748,3,3,10,2 8,3,40.7591699132473,-73.9847476982669,9,7,8,5 8,9,40.7585382646798,-73.98427762401,8,2,5,7 8,5,40.7591325809128,-73.9859416944449,2,3,4,7 1,10,40.7592611607891,-73.9841969481268,8,7,1,2 1,3,40.7579691848779,-73.9841531244925,2,8,1,6 1,1,40.7580401211238,-73.985581492138,3,2,6,10 1,8,40.7586413385701,-73.9846689757252,10,3,6,0 1,7,40.7582596906369,-73.984743276664,8,6,6,4 1,1,40.7593930484598,-73.9844509336994,0,4,6,0 1,5,40.7592530296455,-73.9856903517036,3,7,5,7 1,7,40.7579347945071,-73.9859777377261,8,9,9,0 1,1,40.7583761536871,-73.985834911717,9,8,5,3 1,8,40.7581450762773,-73.9846474281865,2,7,9,8 1,2,40.7586051049932,-73.9856250339732,4,6,2,8 1,8,40.7589391507032,-73.9857582769048,7,7,5,1 1,2,40.7598552355292,-73.9844582986537,9,2,2,5 1,6,40.7580882019504,-73.9842737141497,5,6,10,2 1,8,40.758482203899,-73.984892300622,3,7,8,0 1,4,40.7595600512131,-73.9853101640096,0,5,5,3 1,9,40.7579476152585,-73.9854878299431,6,3,3,2 1,3,40.7597597162114,-73.9860975942206,1,10,8,1 7,3,40.7595991433715,-73.9845124059053,0,1,2,6 7,4,40.7589240646857,-73.9852887547709,8,4,7,6 7,6,40.7582982003354,-73.984795892687,10,0,9,4 7,5,40.7583415660123,-73.9853145215459,3,1,9,9 7,7,40.7582091776255,-73.9846772547321,5,0,5,7 7,0,40.759734659534,-73.9843338904697,0,5,7,0 7,1,40.7594001690942,-73.9854380581019,9,9,10,10 7,9,40.7590412120936,-73.9850591692658,4,0,2,6 7,7,40.7588734937418,-73.9856713185361,3,4,2,2 7,8,40.7586753599794,-73.9848406082056,8,3,4,8 7,5,40.7598752633991,-73.984487231959,3,5,4,3 7,6,40.7592213707949,-73.9846949898339,0,2,5,3 7,2,40.7585497230814,-73.9859657678892,5,3,8,10 7,5,40.7579495843329,-73.9846391945266,10,0,2,5 7,3,40.7590545088692,-73.985204895608,5,1,7,5 7,8,40.7590973448289,-73.9850388495628,1,4,10,7 7,8,40.7589251276777,-73.98548084496,5,0,5,8 7,4,40.7588324825094,-73.985305814383,5,8,3,10 2,5,40.7579735615324,-73.9842997173447,3,7,5,1 2,0,40.7588064078382,-73.9857434038226,3,3,7,0 2,3,40.7588438029234,-73.9853819513693,1,10,2,0 2,2,40.7589889551621,-73.9850063797225,2,3,6,6 2,1,40.7598287909185,-73.9854019674537,6,6,8,2 2,9,40.7579780119989,-73.9860675165336,4,3,7,6 2,0,40.7592434179868,-73.985385958427,1,10,8,0 2,2,40.7597305128403,-73.985350591638,1,10,7,2 2,4,40.7581336771004,-73.9855458280159,0,10,6,7 4,9,40.7594592438155,-73.9856411212472,5,9,4,10 4,2,40.7590960428371,-73.9851565797007,5,8,6,4 4,10,40.7598059624486,-73.9857454456295,9,2,4,7 4,8,40.7588052926572,-73.9843365588932,6,7,9,2 5,6,40.7596997030639,-73.9845484906225,3,4,3,9 5,8,40.7594079103298,-73.9843059319443,9,4,6,4 5,1,40.7580521274005,-73.9848191759981,5,9,9,3 5,2,40.7580591968774,-73.9853747195652,1,7,10,3 5,8,40.7592267197683,-73.9856930289356,4,6,5,9 5,1,40.7593349264903,-73.9848542028534,8,0,6,3 5,1,40.7581897167685,-73.9854442236809,1,5,6,2 10,9,40.7593763320126,-73.985722746896,3,9,1,10 10,7,40.7581679780936,-73.9855977234323,1,5,7,4 10,2,40.7582430664954,-73.9851915615535,10,5,2,8 10,5,40.758919744772,-73.9856768202422,7,9,4,7 10,0,40.7580296377396,-73.9849412224911,2,6,9,9 10,4,40.7588329302399,-73.9842071913517,3,1,10,4 10,8,40.7591101752534,-73.9842493810592,8,5,4,5 10,9,40.758090480168,-73.985085225359,9,2,6,5 10,2,40.7591293557329,-73.9843426210027,8,4,4,6 10,8,40.7582648615032,-73.9858213687925,10,7,9,8 10,10,40.7598125346728,-73.9844107882403,1,9,7,6 10,1,40.7597037591218,-73.9842972417785,6,4,9,0 10,5,40.759266425551,-73.9847140831755,4,4,2,5 10,1,40.7591004658575,-73.9852144306124,2,1,1,7 10,1,40.7597089746358,-73.9860958891319,4,10,9,8 10,9,40.7583202379645,-73.98607786299,8,7,4,3 10,3,40.7598290836421,-73.9853889658273,4,4,8,9 10,6,40.7594440670936,-73.9851675134761,5,4,4,9 10,1,40.7595995113143,-73.9853460876852,8,2,1,6 10,3,40.7591956555719,-73.9849422159539,4,4,9,3 10,2,40.759294507539,-73.9848677072943,1,6,5,7 10,9,40.7591977825459,-73.9843187623293,8,6,9,9 3,1,40.7585935046092,-73.9854441336728,7,0,9,1 3,1,40.759228982465,-73.9850963676305,3,3,8,7 3,9,40.758030982141,-73.9841336344829,6,6,9,6 3,1,40.758715084409,-73.9859045443883,3,0,2,4 3,6,40.7589047791684,-73.985315999431,3,9,4,10 3,9,40.759171358958,-73.985408751551,5,1,3,10 3,4,40.7595074527316,-73.9843717109071,7,1,1,6 3,0,40.7581955873013,-73.9841819500187,9,3,7,9 3,3,40.7594345190028,-73.9852962841391,4,2,6,1 3,1,40.7590129174642,-73.9844062979374,9,2,1,8 3,1,40.759172729659,-73.9854539673146,9,2,4,6 3,5,40.7589785798184,-73.9855022002788,8,8,8,8 3,3,40.7597266024068,-73.9849189526335,8,1,9,4 3,8,40.7592082168056,-73.9844975548823,8,5,4,10 3,6,40.7586728399397,-73.9842586159226,5,1,6,10 3,7,40.7595887803283,-73.9845113334091,10,1,9,9 3,3,40.7598410282178,-73.9843736079879,3,5,8,9 3,6,40.7595902268566,-73.985918375336,9,5,3,8 3,2,40.7588861368425,-73.9846246924609,8,7,2,4 3,1,40.757955951314,-73.9843968936139,2,8,0,2 3,1,40.7593115495635,-73.985858447561,5,4,1,9 3,7,40.7593976605177,-73.9858385586407,2,3,5,2 3,4,40.7584891686818,-73.9859703907724,4,3,7,6 3,6,40.7595548377708,-73.9845896137505,0,5,10,4 3,7,40.758835561731,-73.9848472897489,8,7,4,1 3,2,40.7588991569812,-73.984812421739,2,10,1,3 3,2,40.7588763589902,-73.9856649895324,2,9,1,2 3,5,40.7582791691107,-73.9846166529799,1,8,9,6 6,3,40.7587845130955,-73.9841068085855,6,6,2,7 6,10,40.7596552377293,-73.9854399399882,4,3,6,2 6,2,40.7588913330814,-73.985206265571,7,6,1,5 6,8,40.7586733157533,-73.9857137405886,7,1,5,8 6,8,40.7580679814802,-73.985472745411,7,7,4,8 9,4,40.7587146079518,-73.9844868738134,1,2,2,6 9,9,40.7593981206595,-73.9852633114899,8,3,4,0 9,3,40.7591942572553,-73.9854898190665,6,4,3,0 9,7,40.758148415953,-73.9855082171246,4,1,2,2 9,5,40.7579604690644,-73.9856520136319,8,2,5,3 9,6,40.7592274112507,-73.9851933038401,8,9,7,7 9,4,40.7590423501838,-73.984100669261,7,2,9,7') ui <- fluidPage( fluidRow( column(6, plotOutput("plot_main", click = "plot_click",height = 800)), column(6, leafletOutput("RampMap_Clicked",height = 800)) ), fluidRow( column(3, selectInput( inputId = "SelectX", label = "X-Axis", choices = colnames(Ramps_Summary)[c(2,4,14,15,16,17,19)], selected = colnames(Ramps_Summary)[c(2,4,14,15,16,17,19)][7] )), column(3, selectInput( inputId = "SelectY", label = "Y-Axis", choices = colnames(Ramps_Summary)[c(2,4,14,15,16,17,19)], selected = colnames(Ramps_Summary)[c(2,4,14,15,16,17,19)][6] )), column(3, selectInput( inputId = "FacetX", label = "X-Facet", choices = c("None" = "All", "FC" = "FC", "SC" = "SC", "NET_ANGLE_CHANGE" ="NET_ANGLE_CHANGE", "MAX_ANGLE_CHANGE" = "MAX_ANGLE_CHANGE", "SUM_ANGLE_CHANGE" = "SUM_ANGLE_CHANGE"), selected = c("None" = "All", "FC" = "FC", "SC" = "SC", "NET_ANGLE_CHANGE" ="NET_ANGLE_CHANGE", "MAX_ANGLE_CHANGE" = "MAX_ANGLE_CHANGE", "SUM_ANGLE_CHANGE" = "SUM_ANGLE_CHANGE")[1] )), column(3, selectInput( inputId = "FacetY", label = "Y-Facet", choices = c("None" = ".", "FUNCTIONAL_CLASS" = "FUNCTIONAL_CLASS", "SPEED_CATEGORY" = "SPEED_CATEGORY", "GEO_SIZE" = "GEO_SIZE", "NET_ANGLE_CHANGE" ="NET_ANGLE_CHANGE", "MAX_ANGLE_CHANGE" = "MAX_ANGLE_CHANGE", "SUM_ANGLE_CHANGE" = "SUM_ANGLE_CHANGE"), selected = c("None" = ".", "FUNCTIONAL_CLASS" = "FUNCTIONAL_CLASS", "SPEED_CATEGORY" = "SPEED_CATEGORY", "GEO_SIZE" = "GEO_SIZE", "NET_ANGLE_CHANGE" ="NET_ANGLE_CHANGE", "MAX_ANGLE_CHANGE" = "MAX_ANGLE_CHANGE", "SUM_ANGLE_CHANGE" = "SUM_ANGLE_CHANGE")[1] )) ) ) server <- function(input,output, session){ output$plot_main <- renderPlot({ plot <- ggplot(Ramps_Summary, aes_string(input$SelectX,input$SelectY)) + geom_point(alpha = 0.5, size = 5) + facet_grid(reformulate(input$FacetX,input$FacetY)) plot } ) output$RampMap_Clicked <- renderLeaflet({ Clicked_Point <- nearPoints(Ramps_Summary, input$plot_click, threshold = 10, maxpoints = 1) Ramps_Geom_Clicked <- Ramps_Geom[Ramps_Geom$LINK_ID==Clicked_Point$LINK_ID,] m <- leaflet() %>% addTiles() %>% addCircleMarkers(lng=Ramps_Geom_Clicked$LON, lat=Ramps_Geom_Clicked$LAT, label = paste('Angle Change = ', as.character(round(Ramps_Geom_Clicked$SEG_BEARING_CHANGE_F)), 'Seq Num =', as.character(round(Ramps_Geom_Clicked$SEQ_NUM)) )) %>% setView(lng=mean(Ramps_Geom_Clicked$LON), lat=mean(Ramps_Geom_Clicked$LAT) , zoom=17) m } ) } shinyApp(ui = ui, server = server)
I have a working solution. I changed the sequence of output objects and it works fine now. But I do feel it is a little hacky. If someone has a better reasoning as to why the original case caused a problem, please let me know. library(tidyverse) library(shiny) library(leaflet) set.seed(5) Ramps_Summary = read.csv(text = '"LINK_ID","FC","UNTLD1","SC","UNTLD2","UNTLD3","UNTLD4","UNTLD5","UNTLD6","UNTLD7","UNTLD8","UNTLD9","UNTLD10","SIZE","NET_ANGLE_CHANGE","MAX_ANGLE_CHANGE","SUM_ANGLE_CHANGE","All","LENGTH" 1,7,1,3,6,1,7,8,0,7,9,1,3,8,7,1,9,"All",1 2,7,1,6,8,2,5,5,6,8,8,3,3,7,8,8,1,"All",3 3,3,3,6,7,5,3,5,10,10,10,6,1,8,2,3,5,"All",4 4,7,5,2,7,10,7,2,4,1,6,2,2,7,9,4,6,"All",8 5,7,3,7,3,9,5,1,6,3,7,6,6,9,5,9,2,"All",4 6,4,1,6,6,5,4,7,9,8,1,5,6,2,3,0,6,"All",1 7,9,1,6,2,4,7,9,2,10,5,8,2,5,5,6,9,"All",10 8,8,8,6,4,7,7,9,3,4,8,7,6,8,1,2,8,"All",5 9,6,3,6,2,3,3,2,7,7,9,1,7,9,5,4,6,"All",6 10,0,7,3,0,5,4,1,3,6,6,1,1,8,7,0,6,"All",8') Ramps_Geom = read.csv(text = '"LINK_ID","SEQ_NUM","LAT","LON","SEG_LEN_M","SEG_BEARING_F","SEG_BEARING_CHANGE_F","SEG_BEARING_T" 8,2,40.7584690905452,-73.9854012361834,5,9,6,2 8,9,40.7580278345045,-73.9845919920848,1,4,9,3 8,10,40.7592006631164,-73.9858852190994,0,7,9,1 8,0,40.7586196884458,-73.9844548667748,3,3,10,2 8,3,40.7591699132473,-73.9847476982669,9,7,8,5 8,9,40.7585382646798,-73.98427762401,8,2,5,7 8,5,40.7591325809128,-73.9859416944449,2,3,4,7 1,10,40.7592611607891,-73.9841969481268,8,7,1,2 1,3,40.7579691848779,-73.9841531244925,2,8,1,6 1,1,40.7580401211238,-73.985581492138,3,2,6,10 1,8,40.7586413385701,-73.9846689757252,10,3,6,0 1,7,40.7582596906369,-73.984743276664,8,6,6,4 1,1,40.7593930484598,-73.9844509336994,0,4,6,0 1,5,40.7592530296455,-73.9856903517036,3,7,5,7 1,7,40.7579347945071,-73.9859777377261,8,9,9,0 1,1,40.7583761536871,-73.985834911717,9,8,5,3 1,8,40.7581450762773,-73.9846474281865,2,7,9,8 1,2,40.7586051049932,-73.9856250339732,4,6,2,8 1,8,40.7589391507032,-73.9857582769048,7,7,5,1 1,2,40.7598552355292,-73.9844582986537,9,2,2,5 1,6,40.7580882019504,-73.9842737141497,5,6,10,2 1,8,40.758482203899,-73.984892300622,3,7,8,0 1,4,40.7595600512131,-73.9853101640096,0,5,5,3 1,9,40.7579476152585,-73.9854878299431,6,3,3,2 1,3,40.7597597162114,-73.9860975942206,1,10,8,1 7,3,40.7595991433715,-73.9845124059053,0,1,2,6 7,4,40.7589240646857,-73.9852887547709,8,4,7,6 7,6,40.7582982003354,-73.984795892687,10,0,9,4 7,5,40.7583415660123,-73.9853145215459,3,1,9,9 7,7,40.7582091776255,-73.9846772547321,5,0,5,7 7,0,40.759734659534,-73.9843338904697,0,5,7,0 7,1,40.7594001690942,-73.9854380581019,9,9,10,10 7,9,40.7590412120936,-73.9850591692658,4,0,2,6 7,7,40.7588734937418,-73.9856713185361,3,4,2,2 7,8,40.7586753599794,-73.9848406082056,8,3,4,8 7,5,40.7598752633991,-73.984487231959,3,5,4,3 7,6,40.7592213707949,-73.9846949898339,0,2,5,3 7,2,40.7585497230814,-73.9859657678892,5,3,8,10 7,5,40.7579495843329,-73.9846391945266,10,0,2,5 7,3,40.7590545088692,-73.985204895608,5,1,7,5 7,8,40.7590973448289,-73.9850388495628,1,4,10,7 7,8,40.7589251276777,-73.98548084496,5,0,5,8 7,4,40.7588324825094,-73.985305814383,5,8,3,10 2,5,40.7579735615324,-73.9842997173447,3,7,5,1 2,0,40.7588064078382,-73.9857434038226,3,3,7,0 2,3,40.7588438029234,-73.9853819513693,1,10,2,0 2,2,40.7589889551621,-73.9850063797225,2,3,6,6 2,1,40.7598287909185,-73.9854019674537,6,6,8,2 2,9,40.7579780119989,-73.9860675165336,4,3,7,6 2,0,40.7592434179868,-73.985385958427,1,10,8,0 2,2,40.7597305128403,-73.985350591638,1,10,7,2 2,4,40.7581336771004,-73.9855458280159,0,10,6,7 4,9,40.7594592438155,-73.9856411212472,5,9,4,10 4,2,40.7590960428371,-73.9851565797007,5,8,6,4 4,10,40.7598059624486,-73.9857454456295,9,2,4,7 4,8,40.7588052926572,-73.9843365588932,6,7,9,2 5,6,40.7596997030639,-73.9845484906225,3,4,3,9 5,8,40.7594079103298,-73.9843059319443,9,4,6,4 5,1,40.7580521274005,-73.9848191759981,5,9,9,3 5,2,40.7580591968774,-73.9853747195652,1,7,10,3 5,8,40.7592267197683,-73.9856930289356,4,6,5,9 5,1,40.7593349264903,-73.9848542028534,8,0,6,3 5,1,40.7581897167685,-73.9854442236809,1,5,6,2 10,9,40.7593763320126,-73.985722746896,3,9,1,10 10,7,40.7581679780936,-73.9855977234323,1,5,7,4 10,2,40.7582430664954,-73.9851915615535,10,5,2,8 10,5,40.758919744772,-73.9856768202422,7,9,4,7 10,0,40.7580296377396,-73.9849412224911,2,6,9,9 10,4,40.7588329302399,-73.9842071913517,3,1,10,4 10,8,40.7591101752534,-73.9842493810592,8,5,4,5 10,9,40.758090480168,-73.985085225359,9,2,6,5 10,2,40.7591293557329,-73.9843426210027,8,4,4,6 10,8,40.7582648615032,-73.9858213687925,10,7,9,8 10,10,40.7598125346728,-73.9844107882403,1,9,7,6 10,1,40.7597037591218,-73.9842972417785,6,4,9,0 10,5,40.759266425551,-73.9847140831755,4,4,2,5 10,1,40.7591004658575,-73.9852144306124,2,1,1,7 10,1,40.7597089746358,-73.9860958891319,4,10,9,8 10,9,40.7583202379645,-73.98607786299,8,7,4,3 10,3,40.7598290836421,-73.9853889658273,4,4,8,9 10,6,40.7594440670936,-73.9851675134761,5,4,4,9 10,1,40.7595995113143,-73.9853460876852,8,2,1,6 10,3,40.7591956555719,-73.9849422159539,4,4,9,3 10,2,40.759294507539,-73.9848677072943,1,6,5,7 10,9,40.7591977825459,-73.9843187623293,8,6,9,9 3,1,40.7585935046092,-73.9854441336728,7,0,9,1 3,1,40.759228982465,-73.9850963676305,3,3,8,7 3,9,40.758030982141,-73.9841336344829,6,6,9,6 3,1,40.758715084409,-73.9859045443883,3,0,2,4 3,6,40.7589047791684,-73.985315999431,3,9,4,10 3,9,40.759171358958,-73.985408751551,5,1,3,10 3,4,40.7595074527316,-73.9843717109071,7,1,1,6 3,0,40.7581955873013,-73.9841819500187,9,3,7,9 3,3,40.7594345190028,-73.9852962841391,4,2,6,1 3,1,40.7590129174642,-73.9844062979374,9,2,1,8 3,1,40.759172729659,-73.9854539673146,9,2,4,6 3,5,40.7589785798184,-73.9855022002788,8,8,8,8 3,3,40.7597266024068,-73.9849189526335,8,1,9,4 3,8,40.7592082168056,-73.9844975548823,8,5,4,10 3,6,40.7586728399397,-73.9842586159226,5,1,6,10 3,7,40.7595887803283,-73.9845113334091,10,1,9,9 3,3,40.7598410282178,-73.9843736079879,3,5,8,9 3,6,40.7595902268566,-73.985918375336,9,5,3,8 3,2,40.7588861368425,-73.9846246924609,8,7,2,4 3,1,40.757955951314,-73.9843968936139,2,8,0,2 3,1,40.7593115495635,-73.985858447561,5,4,1,9 3,7,40.7593976605177,-73.9858385586407,2,3,5,2 3,4,40.7584891686818,-73.9859703907724,4,3,7,6 3,6,40.7595548377708,-73.9845896137505,0,5,10,4 3,7,40.758835561731,-73.9848472897489,8,7,4,1 3,2,40.7588991569812,-73.984812421739,2,10,1,3 3,2,40.7588763589902,-73.9856649895324,2,9,1,2 3,5,40.7582791691107,-73.9846166529799,1,8,9,6 6,3,40.7587845130955,-73.9841068085855,6,6,2,7 6,10,40.7596552377293,-73.9854399399882,4,3,6,2 6,2,40.7588913330814,-73.985206265571,7,6,1,5 6,8,40.7586733157533,-73.9857137405886,7,1,5,8 6,8,40.7580679814802,-73.985472745411,7,7,4,8 9,4,40.7587146079518,-73.9844868738134,1,2,2,6 9,9,40.7593981206595,-73.9852633114899,8,3,4,0 9,3,40.7591942572553,-73.9854898190665,6,4,3,0 9,7,40.758148415953,-73.9855082171246,4,1,2,2 9,5,40.7579604690644,-73.9856520136319,8,2,5,3 9,6,40.7592274112507,-73.9851933038401,8,9,7,7 9,4,40.7590423501838,-73.984100669261,7,2,9,7') ui <- fluidPage( fluidRow( column(6, plotOutput("plot_main", click = "plot_click",height = 800)), column(6, leafletOutput("RampMap_Clicked",height = 800)) ), fluidRow( column(3, selectInput( inputId = "SelectX", label = "X-Axis", choices = colnames(Ramps_Summary)[c(2,4,14,15,16,17,19)], selected = colnames(Ramps_Summary)[c(2,4,14,15,16,17,19)][7] )), column(3, selectInput( inputId = "SelectY", label = "Y-Axis", choices = colnames(Ramps_Summary)[c(2,4,14,15,16,17,19)], selected = colnames(Ramps_Summary)[c(2,4,14,15,16,17,19)][6] )), column(3, selectInput( inputId = "FacetX", label = "X-Facet", choices = c("None" = "All", "FC" = "FC", "SC" = "SC", "NET_ANGLE_CHANGE" ="NET_ANGLE_CHANGE", "MAX_ANGLE_CHANGE" = "MAX_ANGLE_CHANGE", "SUM_ANGLE_CHANGE" = "SUM_ANGLE_CHANGE"), selected = c("None" = "All", "FC" = "FC", "SC" = "SC", "NET_ANGLE_CHANGE" ="NET_ANGLE_CHANGE", "MAX_ANGLE_CHANGE" = "MAX_ANGLE_CHANGE", "SUM_ANGLE_CHANGE" = "SUM_ANGLE_CHANGE")[1] )), column(3, selectInput( inputId = "FacetY", label = "Y-Facet", choices = c("None" = ".", "FUNCTIONAL_CLASS" = "FUNCTIONAL_CLASS", "SPEED_CATEGORY" = "SPEED_CATEGORY", "GEO_SIZE" = "GEO_SIZE", "NET_ANGLE_CHANGE" ="NET_ANGLE_CHANGE", "MAX_ANGLE_CHANGE" = "MAX_ANGLE_CHANGE", "SUM_ANGLE_CHANGE" = "SUM_ANGLE_CHANGE"), selected = c("None" = ".", "FUNCTIONAL_CLASS" = "FUNCTIONAL_CLASS", "SPEED_CATEGORY" = "SPEED_CATEGORY", "GEO_SIZE" = "GEO_SIZE", "NET_ANGLE_CHANGE" ="NET_ANGLE_CHANGE", "MAX_ANGLE_CHANGE" = "MAX_ANGLE_CHANGE", "SUM_ANGLE_CHANGE" = "SUM_ANGLE_CHANGE")[1] )) ) ) server <- function(input,output, session){ output$RampMap_Clicked <- renderLeaflet({ Clicked_Point <- nearPoints(Ramps_Summary, input$plot_click, threshold = 10, maxpoints = 1) Ramps_Geom_Clicked <- Ramps_Geom[Ramps_Geom$LINK_ID==Clicked_Point$LINK_ID,] m <- leaflet() %>% addTiles() %>% addCircleMarkers(lng=Ramps_Geom_Clicked$LON, lat=Ramps_Geom_Clicked$LAT, label = paste('Angle Change = ', as.character(round(Ramps_Geom_Clicked$SEG_BEARING_CHANGE_F)), 'Seq Num =', as.character(round(Ramps_Geom_Clicked$SEQ_NUM)) )) %>% setView(lng=mean(Ramps_Geom_Clicked$LON), lat=mean(Ramps_Geom_Clicked$LAT) , zoom=17) m } ) output$plot_main <- renderPlot({ plot <- ggplot(Ramps_Summary, aes_string(input$SelectX,input$SelectY)) + geom_point(alpha = 0.5, size = 5) + facet_grid(reformulate(input$FacetX,input$FacetY)) plot } ) } shinyApp(ui = ui, server = server)
This has been solved here. https://community.rstudio.com/t/plot-does-not-render-unless-some-input-is-changed/18839/3?u=gibran Basically the default state didn't have a selected point to plot on the leaflet plot which caused an error which stopped from anything being displayed. Changing the order solved that without addressing the underlying problem.