R shiny overlay plots












0















I am new to R shiny. I would like to overlay plot3 and plot 6 to Map tab (first tab) with the 2 line charts plots (plot and plot2) respectively. So only when click onto the map, the 2 line charts (plot and plot2) appears in placed of plot3 and plot6.



Sorry for any confusion in labelling of charts.



library(shiny)    # for shiny apps
library(leaflet) # renderLeaflet function
library(ggplot2)
library(plotly)
library(highcharter)
library(treemap)
library(dygraphs)
library(RColorBrewer)
library(shinydashboard)

server = function(input, output) {


Cookedfood_R <- readRDS("~/hawkermaster.rds")
linechart <- readRDS("~/line.rds")
linechart2 <- readRDS("~/linechart2.rds")
exploratory <- readRDS("~/exploratory.rds")
treem <- readRDS("~/treem.rds")
Main <- readRDS("~/Main.rds")
forecast <- readRDS("~/forecast.rds")

#getColor <- function(Cookedfood_R) {
# sapply(Cookedfood_R$TYPE, function(TYPE) {
# if(TYPE == 1) {"blue"}
# else {"orange"} })
#}
icons <- awesomeIcons(
icon = 'ion-close',
iconColor = 'black',
library = 'ion'
#markerColor = getColor(Cookedfood_R)
)

output$map = renderLeaflet({
leaflet() %>% addTiles() %>%
addMarkers(data = Cookedfood_R,
lat = ~ LATITUDE,
lng = ~ LONGITUDE,
icon = icons,
layerId =~HAWKER,
popup = paste(Cookedfood_R$HAWKER, "<br>",
"No. of cooked food stalls:", Cookedfood_R$Cook, "<br>",
"No. of Market stalls:", Cookedfood_R$market,"<br>"))})


# generate data in reactive
ggplot_data <- reactive({
site <- input$map_marker_click$id
linechart[linechart$NEWNAME %in% site,]
})
ggplot_data2 <- reactive({
site <- input$map_marker_click$id
linechart2[linechart2$NEWNAME %in% site,]
})

output$plot <- renderPlotly({
ggplotly(
ggplot(data = ggplot_data(), aes(x = YEAR, y = AVGSQM, color = TYPE))+
geom_line()+theme_bw())
#geom_point(aes(shape=TYPE, size=1))

})
output$plot2 <- renderPlotly({
ggplotly(
ggplot(data = ggplot_data2(), aes(x = YEAR, y = AVG, color = TYPE))+
geom_line()+theme_bw())
#geom_point(aes(shape=TYPE, size=1))

})
output$plot3 <- renderPlotly({
plot_ly(exploratory, x = ~TYPE_OF_STALL, y = ~AVERAGE_BID_PRICE, type = "box", text = rownames(exploratory),
hoverinfo = 'text',
mode = 'markers',
transforms = list(
list(
type = 'filter',
target = 'HAWKER_CENTRE',
operation = '>',
value = unique(exploratory$HAWKER_CENTRE)
)))
})
output$plot4 <- renderPlotly({
plot_ly(Main, y = ~BID_PRICE_PER_SQM, x = ~AGE_OF_HAWKER, color = ~TYPE_OF_STALL, type= "scatter")
})

output$plot5 <- renderHighchart({
tm<-treemap(treem,
index=c("TYPE_OF_STALL", "TRADE"),
vSize="Stall_Count",
vColor="avg_sqm",
type="value",
palette="-RdGy",
range=c(60,2060),
title = "Treemap of Bid Price Per Sqm Across Trade")

hctreemap(tm, allowDrillToNode = TRUE) %>%
hc_title(text = "Treemap of Bid Price Per Sqm Across Trade") %>%
hc_tooltip(pointFormat = "<b>{point.name}</b>:<br>
No. of successful bids: {point.value:,.0f}") %>%
hc_exporting(enabled = TRUE) # enable export
})
output$plot6 <- renderDygraph({
dygraph(forecast)
})


}

#ui <-bootstrapPage(
#tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
#leafletOutput("map", width = "100%", height = "100%"),

ui <-fluidPage(
titlePanel("Visualising Hawkers in Singapore"),
tabsetPanel(
tabPanel("Map", column(8,leafletOutput("map", height="900px")),column(4,br(),br(), plotlyOutput("plot", height="400px")),column(4,br(),br(),plotlyOutput("plot2", height="400px"))),
tabPanel("Exploratory", column(5,br(),br(), plotlyOutput("plot3", height="400px")),column(5,br(),br(), dygraphOutput("plot6", height="400px")), column(5,br(),br(), plotlyOutput("plot4", height="400px")), column(5, br(), br(), highchartOutput("plot5")))),
br()
)
shinyApp(ui = ui, server = server)









share|improve this question




















  • 2





    It'd be great if you could replace your RDS files with some sample data

    – erocoar
    Nov 24 '18 at 13:18
















0















I am new to R shiny. I would like to overlay plot3 and plot 6 to Map tab (first tab) with the 2 line charts plots (plot and plot2) respectively. So only when click onto the map, the 2 line charts (plot and plot2) appears in placed of plot3 and plot6.



Sorry for any confusion in labelling of charts.



library(shiny)    # for shiny apps
library(leaflet) # renderLeaflet function
library(ggplot2)
library(plotly)
library(highcharter)
library(treemap)
library(dygraphs)
library(RColorBrewer)
library(shinydashboard)

server = function(input, output) {


Cookedfood_R <- readRDS("~/hawkermaster.rds")
linechart <- readRDS("~/line.rds")
linechart2 <- readRDS("~/linechart2.rds")
exploratory <- readRDS("~/exploratory.rds")
treem <- readRDS("~/treem.rds")
Main <- readRDS("~/Main.rds")
forecast <- readRDS("~/forecast.rds")

#getColor <- function(Cookedfood_R) {
# sapply(Cookedfood_R$TYPE, function(TYPE) {
# if(TYPE == 1) {"blue"}
# else {"orange"} })
#}
icons <- awesomeIcons(
icon = 'ion-close',
iconColor = 'black',
library = 'ion'
#markerColor = getColor(Cookedfood_R)
)

output$map = renderLeaflet({
leaflet() %>% addTiles() %>%
addMarkers(data = Cookedfood_R,
lat = ~ LATITUDE,
lng = ~ LONGITUDE,
icon = icons,
layerId =~HAWKER,
popup = paste(Cookedfood_R$HAWKER, "<br>",
"No. of cooked food stalls:", Cookedfood_R$Cook, "<br>",
"No. of Market stalls:", Cookedfood_R$market,"<br>"))})


# generate data in reactive
ggplot_data <- reactive({
site <- input$map_marker_click$id
linechart[linechart$NEWNAME %in% site,]
})
ggplot_data2 <- reactive({
site <- input$map_marker_click$id
linechart2[linechart2$NEWNAME %in% site,]
})

output$plot <- renderPlotly({
ggplotly(
ggplot(data = ggplot_data(), aes(x = YEAR, y = AVGSQM, color = TYPE))+
geom_line()+theme_bw())
#geom_point(aes(shape=TYPE, size=1))

})
output$plot2 <- renderPlotly({
ggplotly(
ggplot(data = ggplot_data2(), aes(x = YEAR, y = AVG, color = TYPE))+
geom_line()+theme_bw())
#geom_point(aes(shape=TYPE, size=1))

})
output$plot3 <- renderPlotly({
plot_ly(exploratory, x = ~TYPE_OF_STALL, y = ~AVERAGE_BID_PRICE, type = "box", text = rownames(exploratory),
hoverinfo = 'text',
mode = 'markers',
transforms = list(
list(
type = 'filter',
target = 'HAWKER_CENTRE',
operation = '>',
value = unique(exploratory$HAWKER_CENTRE)
)))
})
output$plot4 <- renderPlotly({
plot_ly(Main, y = ~BID_PRICE_PER_SQM, x = ~AGE_OF_HAWKER, color = ~TYPE_OF_STALL, type= "scatter")
})

output$plot5 <- renderHighchart({
tm<-treemap(treem,
index=c("TYPE_OF_STALL", "TRADE"),
vSize="Stall_Count",
vColor="avg_sqm",
type="value",
palette="-RdGy",
range=c(60,2060),
title = "Treemap of Bid Price Per Sqm Across Trade")

hctreemap(tm, allowDrillToNode = TRUE) %>%
hc_title(text = "Treemap of Bid Price Per Sqm Across Trade") %>%
hc_tooltip(pointFormat = "<b>{point.name}</b>:<br>
No. of successful bids: {point.value:,.0f}") %>%
hc_exporting(enabled = TRUE) # enable export
})
output$plot6 <- renderDygraph({
dygraph(forecast)
})


}

#ui <-bootstrapPage(
#tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
#leafletOutput("map", width = "100%", height = "100%"),

ui <-fluidPage(
titlePanel("Visualising Hawkers in Singapore"),
tabsetPanel(
tabPanel("Map", column(8,leafletOutput("map", height="900px")),column(4,br(),br(), plotlyOutput("plot", height="400px")),column(4,br(),br(),plotlyOutput("plot2", height="400px"))),
tabPanel("Exploratory", column(5,br(),br(), plotlyOutput("plot3", height="400px")),column(5,br(),br(), dygraphOutput("plot6", height="400px")), column(5,br(),br(), plotlyOutput("plot4", height="400px")), column(5, br(), br(), highchartOutput("plot5")))),
br()
)
shinyApp(ui = ui, server = server)









share|improve this question




















  • 2





    It'd be great if you could replace your RDS files with some sample data

    – erocoar
    Nov 24 '18 at 13:18














0












0








0








I am new to R shiny. I would like to overlay plot3 and plot 6 to Map tab (first tab) with the 2 line charts plots (plot and plot2) respectively. So only when click onto the map, the 2 line charts (plot and plot2) appears in placed of plot3 and plot6.



Sorry for any confusion in labelling of charts.



library(shiny)    # for shiny apps
library(leaflet) # renderLeaflet function
library(ggplot2)
library(plotly)
library(highcharter)
library(treemap)
library(dygraphs)
library(RColorBrewer)
library(shinydashboard)

server = function(input, output) {


Cookedfood_R <- readRDS("~/hawkermaster.rds")
linechart <- readRDS("~/line.rds")
linechart2 <- readRDS("~/linechart2.rds")
exploratory <- readRDS("~/exploratory.rds")
treem <- readRDS("~/treem.rds")
Main <- readRDS("~/Main.rds")
forecast <- readRDS("~/forecast.rds")

#getColor <- function(Cookedfood_R) {
# sapply(Cookedfood_R$TYPE, function(TYPE) {
# if(TYPE == 1) {"blue"}
# else {"orange"} })
#}
icons <- awesomeIcons(
icon = 'ion-close',
iconColor = 'black',
library = 'ion'
#markerColor = getColor(Cookedfood_R)
)

output$map = renderLeaflet({
leaflet() %>% addTiles() %>%
addMarkers(data = Cookedfood_R,
lat = ~ LATITUDE,
lng = ~ LONGITUDE,
icon = icons,
layerId =~HAWKER,
popup = paste(Cookedfood_R$HAWKER, "<br>",
"No. of cooked food stalls:", Cookedfood_R$Cook, "<br>",
"No. of Market stalls:", Cookedfood_R$market,"<br>"))})


# generate data in reactive
ggplot_data <- reactive({
site <- input$map_marker_click$id
linechart[linechart$NEWNAME %in% site,]
})
ggplot_data2 <- reactive({
site <- input$map_marker_click$id
linechart2[linechart2$NEWNAME %in% site,]
})

output$plot <- renderPlotly({
ggplotly(
ggplot(data = ggplot_data(), aes(x = YEAR, y = AVGSQM, color = TYPE))+
geom_line()+theme_bw())
#geom_point(aes(shape=TYPE, size=1))

})
output$plot2 <- renderPlotly({
ggplotly(
ggplot(data = ggplot_data2(), aes(x = YEAR, y = AVG, color = TYPE))+
geom_line()+theme_bw())
#geom_point(aes(shape=TYPE, size=1))

})
output$plot3 <- renderPlotly({
plot_ly(exploratory, x = ~TYPE_OF_STALL, y = ~AVERAGE_BID_PRICE, type = "box", text = rownames(exploratory),
hoverinfo = 'text',
mode = 'markers',
transforms = list(
list(
type = 'filter',
target = 'HAWKER_CENTRE',
operation = '>',
value = unique(exploratory$HAWKER_CENTRE)
)))
})
output$plot4 <- renderPlotly({
plot_ly(Main, y = ~BID_PRICE_PER_SQM, x = ~AGE_OF_HAWKER, color = ~TYPE_OF_STALL, type= "scatter")
})

output$plot5 <- renderHighchart({
tm<-treemap(treem,
index=c("TYPE_OF_STALL", "TRADE"),
vSize="Stall_Count",
vColor="avg_sqm",
type="value",
palette="-RdGy",
range=c(60,2060),
title = "Treemap of Bid Price Per Sqm Across Trade")

hctreemap(tm, allowDrillToNode = TRUE) %>%
hc_title(text = "Treemap of Bid Price Per Sqm Across Trade") %>%
hc_tooltip(pointFormat = "<b>{point.name}</b>:<br>
No. of successful bids: {point.value:,.0f}") %>%
hc_exporting(enabled = TRUE) # enable export
})
output$plot6 <- renderDygraph({
dygraph(forecast)
})


}

#ui <-bootstrapPage(
#tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
#leafletOutput("map", width = "100%", height = "100%"),

ui <-fluidPage(
titlePanel("Visualising Hawkers in Singapore"),
tabsetPanel(
tabPanel("Map", column(8,leafletOutput("map", height="900px")),column(4,br(),br(), plotlyOutput("plot", height="400px")),column(4,br(),br(),plotlyOutput("plot2", height="400px"))),
tabPanel("Exploratory", column(5,br(),br(), plotlyOutput("plot3", height="400px")),column(5,br(),br(), dygraphOutput("plot6", height="400px")), column(5,br(),br(), plotlyOutput("plot4", height="400px")), column(5, br(), br(), highchartOutput("plot5")))),
br()
)
shinyApp(ui = ui, server = server)









share|improve this question
















I am new to R shiny. I would like to overlay plot3 and plot 6 to Map tab (first tab) with the 2 line charts plots (plot and plot2) respectively. So only when click onto the map, the 2 line charts (plot and plot2) appears in placed of plot3 and plot6.



Sorry for any confusion in labelling of charts.



library(shiny)    # for shiny apps
library(leaflet) # renderLeaflet function
library(ggplot2)
library(plotly)
library(highcharter)
library(treemap)
library(dygraphs)
library(RColorBrewer)
library(shinydashboard)

server = function(input, output) {


Cookedfood_R <- readRDS("~/hawkermaster.rds")
linechart <- readRDS("~/line.rds")
linechart2 <- readRDS("~/linechart2.rds")
exploratory <- readRDS("~/exploratory.rds")
treem <- readRDS("~/treem.rds")
Main <- readRDS("~/Main.rds")
forecast <- readRDS("~/forecast.rds")

#getColor <- function(Cookedfood_R) {
# sapply(Cookedfood_R$TYPE, function(TYPE) {
# if(TYPE == 1) {"blue"}
# else {"orange"} })
#}
icons <- awesomeIcons(
icon = 'ion-close',
iconColor = 'black',
library = 'ion'
#markerColor = getColor(Cookedfood_R)
)

output$map = renderLeaflet({
leaflet() %>% addTiles() %>%
addMarkers(data = Cookedfood_R,
lat = ~ LATITUDE,
lng = ~ LONGITUDE,
icon = icons,
layerId =~HAWKER,
popup = paste(Cookedfood_R$HAWKER, "<br>",
"No. of cooked food stalls:", Cookedfood_R$Cook, "<br>",
"No. of Market stalls:", Cookedfood_R$market,"<br>"))})


# generate data in reactive
ggplot_data <- reactive({
site <- input$map_marker_click$id
linechart[linechart$NEWNAME %in% site,]
})
ggplot_data2 <- reactive({
site <- input$map_marker_click$id
linechart2[linechart2$NEWNAME %in% site,]
})

output$plot <- renderPlotly({
ggplotly(
ggplot(data = ggplot_data(), aes(x = YEAR, y = AVGSQM, color = TYPE))+
geom_line()+theme_bw())
#geom_point(aes(shape=TYPE, size=1))

})
output$plot2 <- renderPlotly({
ggplotly(
ggplot(data = ggplot_data2(), aes(x = YEAR, y = AVG, color = TYPE))+
geom_line()+theme_bw())
#geom_point(aes(shape=TYPE, size=1))

})
output$plot3 <- renderPlotly({
plot_ly(exploratory, x = ~TYPE_OF_STALL, y = ~AVERAGE_BID_PRICE, type = "box", text = rownames(exploratory),
hoverinfo = 'text',
mode = 'markers',
transforms = list(
list(
type = 'filter',
target = 'HAWKER_CENTRE',
operation = '>',
value = unique(exploratory$HAWKER_CENTRE)
)))
})
output$plot4 <- renderPlotly({
plot_ly(Main, y = ~BID_PRICE_PER_SQM, x = ~AGE_OF_HAWKER, color = ~TYPE_OF_STALL, type= "scatter")
})

output$plot5 <- renderHighchart({
tm<-treemap(treem,
index=c("TYPE_OF_STALL", "TRADE"),
vSize="Stall_Count",
vColor="avg_sqm",
type="value",
palette="-RdGy",
range=c(60,2060),
title = "Treemap of Bid Price Per Sqm Across Trade")

hctreemap(tm, allowDrillToNode = TRUE) %>%
hc_title(text = "Treemap of Bid Price Per Sqm Across Trade") %>%
hc_tooltip(pointFormat = "<b>{point.name}</b>:<br>
No. of successful bids: {point.value:,.0f}") %>%
hc_exporting(enabled = TRUE) # enable export
})
output$plot6 <- renderDygraph({
dygraph(forecast)
})


}

#ui <-bootstrapPage(
#tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
#leafletOutput("map", width = "100%", height = "100%"),

ui <-fluidPage(
titlePanel("Visualising Hawkers in Singapore"),
tabsetPanel(
tabPanel("Map", column(8,leafletOutput("map", height="900px")),column(4,br(),br(), plotlyOutput("plot", height="400px")),column(4,br(),br(),plotlyOutput("plot2", height="400px"))),
tabPanel("Exploratory", column(5,br(),br(), plotlyOutput("plot3", height="400px")),column(5,br(),br(), dygraphOutput("plot6", height="400px")), column(5,br(),br(), plotlyOutput("plot4", height="400px")), column(5, br(), br(), highchartOutput("plot5")))),
br()
)
shinyApp(ui = ui, server = server)






r ggplot2 shiny






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 16:15









James Z

11.2k71935




11.2k71935










asked Nov 24 '18 at 13:14









JoyceJoyce

12




12








  • 2





    It'd be great if you could replace your RDS files with some sample data

    – erocoar
    Nov 24 '18 at 13:18














  • 2





    It'd be great if you could replace your RDS files with some sample data

    – erocoar
    Nov 24 '18 at 13:18








2




2





It'd be great if you could replace your RDS files with some sample data

– erocoar
Nov 24 '18 at 13:18





It'd be great if you could replace your RDS files with some sample data

– erocoar
Nov 24 '18 at 13:18












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458512%2fr-shiny-overlay-plots%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458512%2fr-shiny-overlay-plots%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen