R 在使用plot_geo创建的3D地球仪上单击国家时,是否可以在变量中获取国家名称?
通过参考网站 我在自己的数据上使用plot_geo创建了一个3D地球仪。当我从全球点击某个国家时,我想更新我的SelectInput框 基本上,我想通过另一个图表来更新,该图表将显示我从全球点击的国家的更多细节 有人能帮我用合适的代码来做这件事吗 以下是我的UI和服务器功能:R 在使用plot_geo创建的3D地球仪上单击国家时,是否可以在变量中获取国家名称?,r,shiny,plotly,data-visualization,shinyapps,R,Shiny,Plotly,Data Visualization,Shinyapps,通过参考网站 我在自己的数据上使用plot_geo创建了一个3D地球仪。当我从全球点击某个国家时,我想更新我的SelectInput框 基本上,我想通过另一个图表来更新,该图表将显示我从全球点击的国家的更多细节 有人能帮我用合适的代码来做这件事吗 以下是我的UI和服务器功能: ui <- fluidPage( #Navbar Structure for UI navbarPage("World Happiness R
ui <- fluidPage(
#Navbar Structure for UI
navbarPage("World Happiness Report", theme = shinytheme("lumen"),
tabPanel("Rank Finder", fluid = TRUE, icon = icon("globe-americas"),
fluidRow(
box(
title = "Country Selection Menu",solidHeader = TRUE, status = "primary",
helpText("Please Select a country which you wanted to explore"),
hr(),
selectInput("Country1", "Countries: ", choices = join2019$Country.or.region, selected = "Australia"),
width = 3
),
box(
title = "World Happiness Map: Year 2019", solidHeader = TRUE, status = "primary",
plotlyOutput("Mapoutput"),
width = 8
)
),
fluidRow(
box(
hr(),
width = 3
),
box(
title = "Radar Chart of a selected country", solidHeader = TRUE, status = "primary",
plotlyOutput("Radaroutput"),
width = 8
)
)
))
)
ui%
颜色栏(标题=‘幸福分数’)%>%
布局(geo=g)
})
输出$Radaroutput%布局(极坐标=列表(
径向轴=列表(
可见=T,
范围=c(0100)
)
),
showlegend=F
)
})
}
我的闪亮应用程序如下所示:
# Define server logic required to draw a histogram
server <- function(input, output, session) {
# light grey boundaries
l <- list(color = toRGB("#d1d1d1"), width = 0.5)
# specify map projection/options
g <- list(
showframe = FALSE,
showcoastlines = FALSE,
projection = list(type = 'orthographic'),
resolution = '100',
showcountries = TRUE,
countrycolor = '#d1d1d1',
showocean = TRUE,
oceancolor = '#c9d2e0',
showlakes = TRUE,
lakecolor = '#99c0db',
showrivers = TRUE,
rivercolor = '#99c0db'
)
output$Mapoutput <- renderPlotly({
plot_geo(join2019, source = 'Mapoutput') %>%
add_trace(
z = ~Score, color = ~Score, colors = 'Greens',
# Hover text:
text = ~with(data=join2019, paste("<b>Country:</b> ", Country.or.region,
"<br><b>Region:</b> ", Region,
"<br><b>Happiness Rank: </b>", Overall.rank,
"<br><b>Happiness Score: </b>", Score)),
locations = ~code, marker = list(line = l)) %>%
colorbar(title = 'Happiness Score') %>%
layout( geo = g )
})
output$Radaroutput <- renderPlotly({
SelectedCountry <- join2019%>%filter(Country.or.region == input$Country1)
plot_ly(data = SelectedCountry, type = "scatterpolar",
r = c(~Score*10, ~Generosity*100, ~Perceptions.of.corruption*100, ~Literacy, ~Freedom.to.make.life.choices*100, ~Score*10),
theta = c('Happiness Score', 'Generosity', 'Absence of Corruption', 'Literacy', 'Freedom', 'Happiness Score'),
fill = 'toself') %>% layout(polar = list(
radialaxis = list(
visible = T,
range = c(0,100)
)
),
showlegend = F
)
})
}