我是R Shiny的新手。我想分别用2个折线图绘图(plot和plot2)将plot3和plot 6覆盖到Map选项卡(第一个选项卡)。因此,只有在单击地图时,两个线形图(图和图2)才会出现在图3和图6的位置。
很抱歉在图表标签上出现任何混淆。
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)