我希望在服务器的echarts4r对象中检索用户选择的信息,用于服务器端逻辑。我正在寻找使用回调id_clicked_data,id_mouseover_data等在这里找到https://echarts4r.john-coene.com/reference/echarts4r-shiny.html。
在玩具应用程序(下图)中,我希望返回地图上单击的国家的值,以便通过outpt_map_country对象将该值返回到屏幕。任何帮助都将不胜感谢。
我尝试过input$outpt_map_country_clicked_data的变体,但解决方案暗示了我。
library(shiny)
library(echarts4r)
library(countrycode)
library(dplyr)
ui <- fluidPage(
echarts4rOutput('outpt_map'),
verbatimTextOutput('outpt_map_country'),
tableOutput('out_cns')
)
cns <- data.frame(
country = countrycode::codelist$country.name.en
) %>%
mutate(value = round(runif(length(country), 1, 5), 6))
server <- function(input, output, session) {
output$outpt_map <- renderEcharts4r({
cns %>%
e_charts(country) %>%
e_map(value)
})
output$outpt_map_country <- renderPrint({
input$outpt_map_country_clicked_data
})
output$out_cns <- renderTable({
cns
})
}
shinyApp(ui, server)发布于 2021-04-12 23:28:23
您尝试使用的回调是id_clicked_data,但是您提供的是打印输出的id,而不是地图输出的id。
用input$outpt_map_clicked_data替换input$outpt_map_country_clicked_data,它就可以工作了:
library(shiny)
library(echarts4r)
library(countrycode)
library(dplyr)
ui <- fluidPage(
echarts4rOutput('outpt_map'),
verbatimTextOutput('outpt_map_country'),
tableOutput('out_cns')
)
cns <- data.frame(
country = countrycode::codelist$country.name.en
) %>%
mutate(value = round(runif(length(country), 1, 5), 6))
server <- function(input, output, session) {
output$outpt_map <- renderEcharts4r({
cns %>%
e_charts(country) %>%
e_map(value)
})
output$outpt_map_country <- renderPrint({
input$outpt_map_clicked_data
})
output$out_cns <- renderTable({
cns
})
}
shinyApp(ui, server)https://stackoverflow.com/questions/67060641
复制相似问题