非常感谢有人可以协助解决此错误。 我是R和R闪亮的新手。 将树形图添加到闪亮的应用程序代码后,将出现此错误。我可以知道哪个变量引起了错误:“范围”对因素没有意义。
此外,还附上了tm数据的屏幕截图。范围是不适用。
任何帮助或评论将不胜感激。
library(shiny) # for shiny apps
library(leaflet) # renderLeaflet function
library(ggplot2)
library(plotly)
server = function(input, output) {
Cookedfood_R <- readRDS("~/hawkermaster.rds")
linechart <- readRDS("~/line.rds")
linechart2 <- readRDS("~/linechart2.rds")
exploratory <- readRDS("~/exploratory.rds")
tm <- readRDS("~/tm.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(
tm
,index=c("TYPE_OF_STALL","TRADE")
,vSize="avg_sqm"
,vColor = "TYPE_OF_STALL"
,type="value"
, 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>
Bid Price Per SQM: {point.value:,.0f}") %>%
hc_exporting(enabled = TRUE) # enable export
})
}
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(6,br(),br(), plotlyOutput("plot3", height="400px")), column(6,br(),br(), plotlyOutput("plot4", height="400px")), column(6,br(),br(), plotlyOutput("plot5", height="400px")))),
br()
)
shinyApp(ui = ui, server = server)