Assigning dynamic title to a plotly plot with flexdashboard/crosstalk not working

51 views Asked by At

I have a simple flexdashbaord and a simple data frame assigned to a crosstalk shared data frame and a plotly plot. Everything fine so far Now I would like to assign a dynamic title to the plot. The dynmaic part of the title would be exatly the string selected with the filter_select. But I am not able to pull the data out from the crosstalk df. Additional information: I wold like to avoid Shiny. Can anybody help me?

This is the code:

---
title: "Flexdashboard with crosstalk and plotly and NO Shiny"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
---

```{r}
library(flexdashboard)
library(crosstalk)
library(plotly)

# simple data frame, just for this exercise
data <- data.frame(
  Indicator = c("Indicator1", "Indicator2", "Indicator3", "Indicator4", "Indicator5"),
  Value = c(10, 20, 30, 40, 50)
)

# create a crosstalk shared data object
shared_data <- SharedData$new(data)

filter_select(
  id = "Indicator",
  label = "Select Indicator",
  sharedData = shared_data,
  group = ~Indicator,
  multiple = FALSE
)

fig <- plot_ly(shared_data , x = ~Indicator, y = ~Value,
          name = "Indicator", type = 'bar',color = I('#cccc00')) 
        
# try to get the selected indicator-denomination and to assign it to the variable "plot_title"
# this does not to work
plot_title <- unique(shared_data$Indicator)


# Oviously also assigning the variable content to the plotly plot does not work either
fig <- fig %>%
  layout(title = paste0("Plot Indicator", " ", plot_title), yaxis = list(title = "Wert Indikator"))

fig

```

I try to pull out the selected indicator-denomination from the crosstalk-df and to assign it to a variable This does not work: plot_title <- unique(shared_data$Indicator)

0

There are 0 answers