首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在闪亮的应用程序中通过echarts4r使用回调

如何在闪亮的应用程序中通过echarts4r使用回调
EN

Stack Overflow用户
提问于 2021-04-12 22:53:12
回答 1查看 26关注 0票数 1

我希望在服务器的echarts4r对象中检索用户选择的信息,用于服务器端逻辑。我正在寻找使用回调id_clicked_dataid_mouseover_data等在这里找到https://echarts4r.john-coene.com/reference/echarts4r-shiny.html

在玩具应用程序(下图)中,我希望返回地图上单击的国家的值,以便通过outpt_map_country对象将该值返回到屏幕。任何帮助都将不胜感谢。

我尝试过input$outpt_map_country_clicked_data的变体,但解决方案暗示了我。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-12 23:28:23

您尝试使用的回调是id_clicked_data,但是您提供的是打印输出的id,而不是地图输出的id。

input$outpt_map_clicked_data替换input$outpt_map_country_clicked_data,它就可以工作了:

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67060641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档