RShiny branched successive inputs - r
EDIT: Updated with a slightly better code.
I'm working on a very clunky UI that has branches of inputs....but I'm wondering if I should be doing it a different way, possibly on the server side? I want to progress down through the inputs as each one is selected, and to not show the next input until the previous is set. Ultimately each decision tree leads to a data table being displayed from a server side SQL function. (I created two similar functions, one which renders a table with a single select, and one that renders with multi select. Then the selected rows from the table will be sent back to the server along with the inputs via a submit button.
Ultimately I am trying to augment this app: https://shiny.rstudio.com/gallery/phylo-tree-view-subset.html
to have a branch that lets a user manipulate custom data, and then feed it back to the tree plotting function.
Should I be trying to do this sort of input structure on the server instead of UI? If so, is there a decent example somewhere? I'm struggling trying to see how the various demos would work with this.
I have a tree of inputs like so:
1) Do you have a file to upload? (yes/no)
a)Yes
1)File type (list)
2)Choose file (file explorer)
b)No
1)Choose single sample or multiple sample: (single/multiple)
a)Single
1)choose type: (otu/sequence)
a)anychoice
1)Abundance or Incidence? (abundance/incidence)
a)abundance
1)Slider for value between 0-10,000
2)Distance method (list of options)
3) Display datatable (select single row)
4) Submit button
a)Multiple
1)choose type: (otu/sequence)
a)anychoice
1)Abundance or Incidence? (abundance/incidence)
a)abundance
1)Slider for value between 0-10,000
2)Cluster method (list of options)
3)Distance method (list of options)
4) Display datatable (select multiple rows)
5) Submit button
Current code, its not giving all the functionality I want, but I'm still chipping away at it.
ui.R
library(shiny)
library(shinyjs)
library(shinyalert)
ui <- shinyUI(tagList(
useShinyalert(),
useShinyjs(),
navbarPage(
title = "Phylogenetic Tree Subsetting",
tabPanel(
title = "Explore Tree",
fluidRow(
class = "inputs",
column(
4,
selectInput(
inputId = "own_file",
label = "Do you already have a tree file to upload?",
choices = c("No" = "no",
"Yes" = "yes",
" " = " "),
selected = " "
)
),
conditionalPanel(condition = "input.own_file == 'yes'",
column(
4,
selectInput(
inputId = "file_type",
label = "Select Tree File Type:",
choices = c(
"Tree" = "tree",
"Beast" = "beast",
# "CodeML" = "codeml",
"CodeML mlc" = "mlc",
# "HYPHY" = "hyphy",
"jplace" = "jplace",
"MrBayes" = "mrbayes",
"NHX" = "nhx",
"rst (CODEML/BASEML)" = "rst",
"phylip" = "phylip",
# "r8s" = "r8s",
"RAxML" = "raxml"
),
selected = "tree"
)
),
column(
4,
fileInput(inputId = "upload_tree",
label = "Select Tree File:")
)),
conditionalPanel(
condition = "input.own_file == 'no'",
column(
4,
selectInput(
inputId = "tree_type",
label = "Would you like to view a single sample, or cluster multiple samples?",
choices = c(
"Single" = "single",
"Multiple" = "multiple",
" " = " "
),
selected = " "
)
),
conditionalPanel(
condition = "input.tree_type == 'single'",
column(
4,
selectInput(
inputId = "cluster_type1",
label = "View by Organism, or by Sequence?",
choices = c(
Choose = '',
OTU = 'otu',
Sequence = 'sequence'
),
selectize = FALSE
)
),
conditionalPanel(
condition = "input.cluster_type1 == 'sequence'|input.cluster_type1 == 'otu'",
column(
4,
selectInput(
inputId = "presence_type1",
label = "Generate tree from Presence/Absence, or Relative Abundance?",
choices = c(
Choose = '',
Incidence = 'incidence',
Abundance = 'abundance'
),
selectize = FALSE
)
),
conditionalPanel(condition = "input.presence_type1 == 'abundance'",
column(
4,
sliderInput(
"norm_value1",
"Choose normalization value: (Use keyboard arrows to fine tune value.)",
min = 0,
max = 10000,
value = 3999
)
)),
conditionalPanel(
condition = "input.presence_type1 == 'incidence'|input.presence_type1 == 'abundance'",
column(
4,
selectInput(
inputId = "distance_method1",
label = "Which distance method would you like to use for the distance matrix?",
choices = c(
"Manhattan" = "manhattan",
"Canberra" = "canberra",
"Bray" = "bray",
"Kulczynski" = "kulczynski",
"Jaccard" = "jaccard",
"Gower" = "gower",
"AltGower" = "altGower",
"Morisita" = "morisita",
"Horn" = "horn",
"Mountford" = "mountford",
"Raup" = "raup",
"Binomial" = "binomial",
"Chao" = "chao",
"Cao" = "cao",
"Mahalanobis" = "mahalanobis"
),
selected = "gower"
)
),
conditionalPanel(condition = "input.distance_method1 == 'bray'|input.norm_value1 == '4000'",
column(
4,
DT::dataTableOutput("tbl1"),
actionButton(
"button",
"SUBMIT",
style = "background-color:#221B70;
color:#E0EB15;
border-color:#E61029;
border-style:double;
border-width:4px;
border-radius:50%;
font-size:19px;"
)
))
)
)
)
),
conditionalPanel(
condition = "input.tree_type == 'multiple'",
column(
4,
selectInput(
inputId = "cluster_type2",
label = "View by Organism, or by Sequence?",
choices = c(
Choose = '',
OTU = 'otu',
Sequence = 'sequence'
),
selectize = FALSE
)
),
conditionalPanel(
condition = "input.cluster_type2 == 'sequence'|input.cluster_type2 == 'otu'",
column(
4,
selectInput(
inputId = "presence_type2",
label = "Generate tree from Presence/Absence, or Relative Abundance?",
c(
Choose = '',
Incidence = 'incidence',
Abundance = 'abundance'
),
selectize = FALSE
)
),
conditionalPanel(condition = "input.presence_type2 == 'abundance'",
column(
4,
sliderInput(
"norm_value2",
"Choose normalization value: (Use keyboard arrows to fine tune value.)",
min = 0,
max = 10000,
value = 3999
)
)),
conditionalPanel(
condition = "input.presence_type2 == 'incidence'|input.presence_type2 == 'abundance'",
column(
4,
selectInput(
inputId = "cluster_method",
label = "Which clustering method would you like to use?",
choices = c(
"Ward.D" = "ward.D",
"Ward.D2" = "ward.D2",
"Single" = "single",
"Complete" = "complete",
"Average (= UPGMA)" = "average",
"Mcquitty (= WPGMA)" = "mcquitty",
"Median (= WPGMC)" = "median",
"Centroid (= UPGMC)" = "centroid"
),
selected = "single"
)
),
conditionalPanel(
condition = "input.cluster_method == 'ward.D2'",
column(
4,
selectInput(
inputId = "distance_method2",
label = "Which distance method would you like to use for the distance matrix?",
choices = c(
"Manhattan" = "manhattan",
"Canberra" = "canberra",
"Bray" = "bray",
"Kulczynski" = "kulczynski",
"Jaccard" = "jaccard",
"Gower" = "gower",
"AltGower" = "altGower",
"Morisita" = "morisita",
"Horn" = "horn",
"Mountford" = "mountford",
"Raup" = "raup",
"Binomial" = "binomial",
"Chao" = "chao",
"Cao" = "cao",
"Mahalanobis" = "mahalanobis"
),
selected = "gower"
)
),
conditionalPanel(
condition = "input.distance_method2 == 'bray'|input.norm_value2 == '4000'",
DT::dataTableOutput("tbl2"),
actionButton(
"button",
"SUBMIT",
style = "background-color:#221B70;
color:#E0EB15;
border-color:#E61029;
border-style:double;
border-width:4px;
border-radius:50%;
font-size:19px;"
)
)
)
)
)
)
),
uiOutput("select_node_render"),
fluidRow(uiOutput("subtree_render"))
)
)
))
server <- function(input, output){
}
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)
Map either numerical values or a character string
I'm trying to create a ShinyApp and hoping I could get some pointers. I'm trying to get a summary table ("Summary score") to represent either i) the minimum value associated with user input for radio buttons (e.g., Id037_crit1 & Id038_crit1) or the text string "NA" if a checkbox is selected (Id039_crit1). I'm not sure how to change the code such that the summary table shows either the minimum value for the radio buttons or the character string if the checkbox is selected. I'm assuming there's some kind of if-else statement but I can't get it to work. library(shinydashboard) library(shinythemes) library(shiny) library(shinyWidgets) library(DT) library(tidyverse) ui <- fluidPage( theme = shinytheme("united"), # Application title titlePanel("TITLE"), sidebarLayout( sidebarPanel( selectInput("select", label = helpText("Select a critera"), choices = list("Criteria_1", "Criteria_2"), selected = c("NULL") ) ), mainPanel(tabsetPanel( tabPanel( "Criteria", conditionalPanel(h3("Question 1", align = "left"), condition = "input.select == 'Criteria_1'", prettyRadioButtons( inputId = "Id037_crit1", label = "Predictions:", choices = c( "Option 1" = 1, "Option 2" = 2, "Option 3" = 3 ), inline = TRUE, status = "danger", fill = TRUE ), ), conditionalPanel(h3("Question 2", align = "left"), condition = "input.select == 'Criteria_1'", prettyRadioButtons( inputId = "Id038_crit1", label = "Hypotheses:", choices = c( "Option 1" = 1, "Option 2" = 2, "Option 3" = 3 ), inline = TRUE, status = "danger", fill = TRUE) ), conditionalPanel(h3("Or", align = "left"), condition = "input.select == 'Criteria_1'", awesomeCheckbox( inputId = "Id039_crit1", label = "NA", status = "danger") ), # User side-pannel selection - criteria 2 conditionalPanel(h3("Question 1", align = "left"), condition = "input.select == 'Criteria_2'", prettyRadioButtons( inputId = "Id040_crit2", label = "Methods:", choices = c( "Option 1" = 1, "Option 2" = 2 ), inline = TRUE, status = "danger", fill = TRUE)), # Second Tab -------------------------------------------------------------- tabPanel( "Summary score", DTOutput("summary") ), )) ) ) # SERVER ------------------------------------------------------------------ server <- function(input, output) { calc_min_val <- function(contains) { radios_inputid <- str_subset(names(input), contains) map_dbl(radios_inputid, ~ as.numeric(input[[.x]])) %>% min() } summ <- reactive({ min_values <- c("crit1$", "crit2$") %>% map(calc_min_val) tibble( Lowest_Criteria = c("Specific hypotheses and prediction are provided?", "Predictions regarding the electromagnetic area of interest are sufficient?"), value = map(min_values, ~.) ) }) output$summary <- DT::renderDT({ datatable(summ()) }) # Downloadable csv of selected dataset ---- output$downloadData <- downloadHandler( filename = function() { paste("DATA", ".csv", sep = "") }, content = function(file) { write.csv(datasettable(summ()), file, row.names = FALSE) } ) } shinyApp(ui, server)
Perhaps you are looking for this summ <- reactive({ min_values <- c("crit1$", "crit2$") %>% map(calc_min_val) if (input$Id039_crit1 & input$select == 'Criteria_1') value = "NA" else value = map(min_values, ~.) tibble( Lowest_Criteria = c("Specific hypotheses and prediction are provided?", "Predictions regarding the electromagnetic area of interest are sufficient?"), value = value ) })
Trying to create a reactive graph that will take in multiple different inputs in shiny
I have added multiple select inputs to my shiny app in the sidebar and in the main body and want to create a graph that will change when any of those inputs have been selected or changed but I keep getting the error Warning: Error in : Result must have length 56127, not 0. UI: ui <- dashboardPage( dashboardHeader(title = "Human Trafficking"), dashboardSidebar( sidebarMenu( selectInput("Source", "Choose a Data Source: ", choices = " ", selected = NULL, multiple = TRUE, selectize = TRUE, width = NULL, size = NULL), dateInput("startdate", "Start Date:", value = "2009-01-01", format = "dd-mm-yyyy", min = "2009-01-01", max = "2019-08-26"), dateInput("enddate", "End Date:", value = "2019-08-27", format = "dd-mm-yyyy", min = "2009-01-02", max = "2019-08-27"), selectInput("Nationality", "Select a nation: ", choices = " "), actionButton("button", "Apply") ) ), dashboardBody( fluidRow( box(width = 4, solidHeader = TRUE, selectInput("traffickingType", "Choose a trafficking type: ", choices = " ", selected = NULL, multiple = TRUE, selectize = TRUE, width = NULL, size = NULL) ), box(width = 4, solidHeader = TRUE, selectInput("traffickingSubType", "Choose a trafficking sub type: ", choices = " ", selected = NULL, multiple = TRUE, selectize = TRUE, width = NULL, size = NULL) ), box(width = 4, solidHeader = TRUE, selectInput("gender", "Choose a gender: ", choices = " ", selected = NULL, multiple = TRUE, selectize = TRUE, width = NULL, size = NULL) ) ), fluidRow( box(width = 12, plotlyOutput('coolplot') ) ) ) ) Server: server <- function(input, output, session) { genderVic = sort(unique(ngo$Victim.Gender)) updateSelectInput(session, "gender", choices = genderVic) traffickingSub = sort(unique(ngo$Trafficking.Sub.Type)) updateSelectInput(session, "traffickingSubType", choices = traffickingSub) trafficking = sort(unique(ngo$Trafficking.Type)) updateSelectInput(session, "traffickingType", choices = trafficking) traffickerNationalities = sort(unique(ngo$Trafficker.Nationality)) updateSelectInput(session, "TraffickerNation", choices = traffickerNationalities) dataSource = sort(unique(ngo$Data.Provided.By)) updateSelectInput(session, "Source", choices = dataSource) nationalities = sort(unique(ngo$Victim.Nationality)) updateSelectInput(session, "Nationality", choices = nationalities) output$coolplot <- renderPlotly({ ngo <- ngo %>% filter(Victim.Nationality == input$Nationality, Victim.Gender == input$gender, Trafficking.Type == input$traffickingType ) p = ggplot(ngo, aes(x = Victim.Age, fill = Trafficking.Type)) + geom_bar(position = "stack") ggplotly(p) %>% layout(showlegend = FALSE) }) } So currently only have it calling three of the inputs to test it but still getting an error.
It should work after the error is displayed once you select a gender and trafficking type in your example. The reason for the error is that renderPlotly is expecting values for input$traffickingType and input$gender but these start out as NULL. Add a req for each of those selectInputs: output$coolplot <- renderPlotly({ ngo <- ngo %>% filter(Victim.Nationality == input$Nationality, Victim.Gender == req(input$gender), Trafficking.Type == req(input$traffickingType) ) p = ggplot(ngo, aes(x = Victim.Age, fill = Trafficking.Type)) + geom_bar(position = "stack") ggplotly(p) %>% layout(showlegend = FALSE) })
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.
Shiny radio button not getting rendered initially when the app starts
I am doing some timeseries analysis and have created a shiny app where when the app starts sample timeseries data is uploaded or the user can upload csv dataset from his local directory.... Sample Dataset: df month passengers 1 01-01-2000 2072798 2 01-02-2000 2118150 3 01-03-2000 2384907 4 01-04-2000 2260620 5 01-05-2000 2386165 6 01-06-2000 2635018 7 01-07-2000 2788843 8 01-08-2000 2942082 9 01-09-2000 2477000 10 01-10-2000 2527969 11 01-11-2000 2161170 12 01-12-2000 2175314 13 01-01-2001 2307525 14 01-02-2001 2196415 15 01-03-2001 2545863 library(signal) library(shiny) library(AnomalyDetection) #devtools::install_github("twitter/AnomalyDetection") library(ggplot2) # Define UI for application that draws a histogram library(shinydashboard) library(shinycssloaders) library(googleVis) shinyUI(dashboardPage(skin = "green", dashboardHeader(title = "Anomaly Detection in Time series", titleWidth = 350), dashboardSidebar( sidebarUserPanel("Nishant Upadhyay", image = "nishantcofyshop.jpg" ), sidebarMenu( menuItem("Data", tabName = "data", icon = icon("database")), menuItem("Filters", tabName = "filter", icon = icon("filter")), menuItem("Anomalies", tabName = "anomaly", icon = icon("check")), #menuItem("Save Data", tabName = "save", icon = icon("save")) menuItem("About The App", tabName = "Help", icon = icon("info-circle")) ) ), dashboardBody( tabItems( tabItem(tabName = "data", fluidRow( box( title = "Data scatter Chart", status = "primary", solidHeader = T, collapsible = T, width = 12, shinycssloaders::withSpinner(htmlOutput("dataChart"),type = getOption("spinner.type", default = 8),color = "red") ) ), fluidRow( box( radioButtons( "data_input","", choices = list("Load sample data" = 1, "Upload csv file" = 2 ) ), conditionalPanel( condition = "input.data_input=='1'", h5("Sample dataset of Lebron James basketball shots over the years") ), conditionalPanel( condition = "input.data_input=='2'", fileInput('file1', 'Choose file to upload', accept = c( 'text/csv', 'text/comma-separated-values', 'text/tab-separated-values', 'text/plain', '.csv', '.tsv' )), checkboxInput('header', 'Header', TRUE), radioButtons('sep', 'Separator', c(Comma=',', Semicolon=';', Tab='\t'),','), radioButtons('quote', 'Quote', c('None'='', 'Double Quote'='"', 'Single Quote'="'"), '') ), title = "Select Dataset", status = "info", solidHeader = T, collapsible = T ), box( title = "Data", status = "info", solidHeader = T, collapsible = T, shinycssloaders::withSpinner(htmlOutput('contents'),type = getOption("spinner.type", default = 8),color = "red") )# end of box )## end of Fluid row ), ## end of tab item tabItem( tabName = "filter", fluidRow( box( title = "Data Chart", status = "primary", solidHeader = T, collapsible = T, width = 12, shinycssloaders::withSpinner(htmlOutput('dataChartFiltered'),type = getOption("spinner.type", default = 8),color = "red") ) ), fluidRow( box( title = "Filters", status = "info", solidHeader = T, collapsible = T, width = 4, radioButtons("filt", NULL, c("None" = "none", "Butterworth" = "butt", "Type-II Chebyshev" = "cheby2")), submitButton("Filter") ), box( title = "Butterworth", status = "info", solidHeader = T, collapsible = T, width = 4, textInput("buttern", label = "Filter Order", value = "3"), textInput("butterf", label = "Critical Frequencies", value = "0.1"), radioButtons("buttert", "Type", c("Low-Pass" = "low", "High-Pass" = "high")) ), box( title = "Chebyshev", status = "info", solidHeader = T, collapsible = T, width = 4, textInput("chebyn", label = "Filter Order", value = "5"), textInput("chebyd", label = "dB of Pass Band", value = "20"), textInput("chebyf", label = "Critical Frequencies", value = "0.2"), radioButtons("chebyt", "Type", c("Low-Pass" = "low", "High-Pass" = "high")) ) ) ) ) ## end of tab items ) ## end of Dashboard ) ) shinyServer(function(input, output){ dataframe<-reactive({ if (input$data_input == 1) { tab <- read.csv("df.csv",header = T,stringsAsFactors = F) } else if (input$data_input == 2) { inFile <- input$file1 if (is.null(inFile)) return(data.frame(x = "Select your datafile")) tab = read.csv(inFile$datapath, header = input$header, sep = input$sep, quote = input$quote) } tt <- tryCatch(as.POSIXct(tab[,1]),error=function(e) e, warning=function(w) w) if (is(tt,"warning") | is(tt,"error")) { tab$Old = tab[,1] tab[,1] = as.POSIXct(1:nrow(tab), origin = Sys.time()) } else { tab[,1] = as.POSIXct(tab[,1]) } tab }) output$dataChart <- renderGvis({ if (!is.null(dataframe())) gvisLineChart(dataframe()[,c(1,2)], xvar = colnames(dataframe())[1], yvar = colnames(dataframe())[2], options = list( crosshair.trigger = 'selection', enableInteractivity = TRUE, hAxis.maxTextLines = 10, tooltip.trigger = 'none' )) }) output$contents <- renderGvis({ if (!is.null(dataframe())) gvisTable(dataframe(), options = list(page='enable')) }) output$dataChartFiltered <- renderGvis({ if (input$filt == "none") { return(NULL) } else if (input$filt == "butt") { bf <- butter(as.numeric(input$buttern), as.numeric(input$butterf), type = input$buttert) filtered = data.frame(timestamp = dataframe()[,1], count = as.numeric(filter(bf, dataframe()[,2]))) gvisLineChart(filtered, xvar = colnames(filtered)[1], yvar = colnames(filtered)[2], options = list( crosshair.trigger = 'selection', enableInteractivity = TRUE, hAxis.maxTextLines = 10, tooltip.trigger = 'none' )) } else if (input$filt == "cheby2") { ch <- cheby2(as.numeric(input$chebyn), as.numeric(input$chebyd), as.numeric(input$chebyf), type = input$chebyt) filtered = data.frame(timestamp = dataframe()[,1], count = as.numeric(filter(ch, dataframe()[,2]))) gvisLineChart(filtered, xvar = colnames(filtered)[1], yvar = colnames(filtered)[2], options = list( crosshair.trigger = 'selection', enableInteractivity = TRUE, hAxis.maxTextLines = 10, tooltip.trigger = 'none' )) } }) }) The problem i am facing is that once the shiny app is executed , the sample data is loaded properly as the this data is placed in the app folder in the directory (one can use R inbuilt data set or use the data i gave in the start) and subsequently all steps gets executed properly. But if i want to upload some other csv file from local directory, the upload button selection does not get activated even after selecting it.But,in fact, if one goes to the second menu item in the sidebar panel i.e. filter tab and clicks on the filter button (under Filters box ) and then if i go back to Data menu in the sidebar panel again, i can see that now my upload csv file button has got activated and now i can browse the csv file in local directory and upload the same into the app and now everything works fine. It seems somewhere the condition that makes the upload file button is not getting active initially when the app opens.... Need help to sort out the issue...Sorry for posting large chunk of code....
conditionalPanel and submitButton do not work well together. Replace your submitButton("Filter") with actionButton("Filter", ""). EDIT: As per the comment, for the plot to be generated only after the actionButton is clicked you can put output$dataChartFiltered inside observeEvent of Filter with isolate for `input objects as follows: observeEvent(input$Filter,{ output$dataChartFiltered <- renderGvis({ if (isolate(input$filt) == "none") { return(NULL) } else if (isolate(input$filt) == "butt") { bf <- butter(as.numeric(isolate(input$buttern)), as.numeric(isolate(input$butterf)), type = isolate(input$buttert)) filtered = data.frame(timestamp = dataframe()[,1], count = as.numeric(filter(bf, dataframe()[,2]))) gvisLineChart(filtered, xvar = colnames(filtered)[1], yvar = colnames(filtered)[2], options = list( crosshair.trigger = 'selection', enableInteractivity = TRUE, hAxis.maxTextLines = 10, tooltip.trigger = 'none' )) } else if (isolate(input$filt) == "cheby2") { ch <- cheby2(as.numeric(isolate(input$chebyn)), as.numeric(isolate(input$chebyd)), as.numeric(isolate(input$chebyf)), type = isolate(input$chebyt)) filtered = data.frame(timestamp = dataframe()[,1], count = as.numeric(filter(ch, dataframe()[,2]))) gvisLineChart(filtered, xvar = colnames(filtered)[1], yvar = colnames(filtered)[2], options = list( crosshair.trigger = 'selection', enableInteractivity = TRUE, hAxis.maxTextLines = 10, tooltip.trigger = 'none' )) } }) })