与传单地图结合使用时,在启动应用程序时不渲染
Plot not rendering on starting an app when combined with leaflet map
我对这个 Shiny 应用程序有疑问:
闪亮的应用程序具有以下结构(下面粘贴了完整的代码):
ui <- fluidPage(
fluidRow(
column(6, plotOutput("plot_main", click = "plot_click",height = 800)),
column(6, leafletOutput("Map_Clicked",height = 800))
),
fluidRow(...))
"plot_main"是使用ggplot2生成的,"Map_Clicked"是使用leaflet生成的。一切正常,除了 "plot_main" 不会呈现,除非我更改它的一些输入。例如,如果我什至更改浏览器的大小 window,就会呈现该图。即使我将它恢复到原始大小,它也会再次渲染并且一切正常。
此外,如果我在没有地图的情况下显示地块,它也可以渲染。只有当我将它们放在同一个流体行中时,它才会在启动时呈现。以前有其他人遇到过这种情况吗?
谢谢。
更新(工作示例):
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)
我有一个可行的解决方案。我更改了输出对象的顺序,现在可以正常工作了。但我确实觉得它有点hacky。如果有人对原始案例导致问题的原因有更好的推理,请告诉我。
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)
这里已经解决了。
https://community.rstudio.com/t/plot-does-not-render-unless-some-input-is-changed/18839/3?u=gibran
基本上,默认状态没有选定的点来绘制在传单图上,这导致错误停止显示任何内容。更改顺序解决了这个问题,但没有解决根本问题。
我对这个 Shiny 应用程序有疑问:
闪亮的应用程序具有以下结构(下面粘贴了完整的代码):
ui <- fluidPage(
fluidRow(
column(6, plotOutput("plot_main", click = "plot_click",height = 800)),
column(6, leafletOutput("Map_Clicked",height = 800))
),
fluidRow(...))
"plot_main"是使用ggplot2生成的,"Map_Clicked"是使用leaflet生成的。一切正常,除了 "plot_main" 不会呈现,除非我更改它的一些输入。例如,如果我什至更改浏览器的大小 window,就会呈现该图。即使我将它恢复到原始大小,它也会再次渲染并且一切正常。
此外,如果我在没有地图的情况下显示地块,它也可以渲染。只有当我将它们放在同一个流体行中时,它才会在启动时呈现。以前有其他人遇到过这种情况吗?
谢谢。
更新(工作示例):
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)
我有一个可行的解决方案。我更改了输出对象的顺序,现在可以正常工作了。但我确实觉得它有点hacky。如果有人对原始案例导致问题的原因有更好的推理,请告诉我。
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)
这里已经解决了。 https://community.rstudio.com/t/plot-does-not-render-unless-some-input-is-changed/18839/3?u=gibran 基本上,默认状态没有选定的点来绘制在传单图上,这导致错误停止显示任何内容。更改顺序解决了这个问题,但没有解决根本问题。