如何解决如何在 Shiny 应用程序中通过 echarts4r 使用回调
我希望在服务器的 echarts4r 对象中检索用户选择的信息,用于服务器端逻辑。我希望使用 https://echarts4r.john-coene.com/reference/echarts4r-shiny.html 处的回调 id_clicked_data
、id_mouSEOver_data
等。
在玩具应用程序(下方)中,我希望返回地图上点击的国家/地区的值,以通过 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)
解决方法
您尝试使用的回调是 id_clicked_data
,但您提供的是打印输出的 ID,而不是地图输出。
将 input$outpt_map_country_clicked_data
替换为 input$outpt_map_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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。