Dynamic shinydashboard::box() with clicked_data

I am developing a shiny app where I am trying to show the plots inside box function from shinydashboard package. For 1st plot I can use the box() function in UI element.

But for 2nd plot, the plot and the box should come after I click a bar of 1st plot. So I have used box in server function and made it dynamic. But I am not getting any information form click_data if I click any point in 2nd plot.

Please check the code below:

library(shiny)
library(shinydashboard)
library(echarts4r)

ui <- dashboardPage(
  dashboardHeader(title = 'Application'),
  dashboardSidebar(),
  dashboardBody(
    box(echarts4rOutput('chart'), title = 'Species', solidHeader = TRUE, status = 'primary'),
    verbatimTextOutput('text'),
    uiOutput('chart1'),
    verbatimTextOutput('text1')
  )
)

server <- function(input, output, session) {
  data <- reactive(iris)
  
  output$chart <- renderEcharts4r({
    data() %>%
      e_charts(Species) %>%
      e_bar(Sepal.Length)
  })
  
  output$text <- renderText({
    input$chart_clicked_data$value[1]
  })
  
  updateData <- reactive({
    filter(data(), Species %in% input$chart_clicked_data$value[1])
  })
  
  f_chart <- reactive({
    validate(need(nrow(updateData()) > 0, ' '))
    updateData() %>%
      e_charts(Sepal.Length) %>%
      e_scatter(Sepal.Width, symbol_size = 6)
  })
  
  output$chart1 <- renderUI({
    req(f_chart())
    box(renderEcharts4r(f_chart()), title = 'Length vs Width', solidHeader = TRUE, status = 'primary')
  })
  
  output$text1 <- renderText({
    input$chart1_clicked_data$value
  })
}

shinyApp(ui, server)

So, no value is rendering from text1. Is it possible to make dynamic box and render information from clicked_data at the same time?

Thanks in advance.

You have a sort of nameless/anonymous chart here, so you wont get clicks from it.
try

 
  output$chart1_really <- renderEcharts4r(f_chart())
  output$chart1 <- renderUI({
    req(f_chart())
    box(echarts4rOutput("chart1_really"),
      title = "Length vs Width",
      solidHeader = TRUE, status = "primary"
    )
  })
  output$text1 <- renderText({
    input$chart1_really_clicked_data$value
  })

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.