Ist es möglich, ein "On-Click" -Ereignis zu einem tremaphapify-Objekt in R Shiny zu machen? Ich habe den folgenden Code für andere Arten von ggplot2 Objekten getestet und es funktioniert. Wenn es eine andere Möglichkeit gibt, ein "On-Click" -Event für eine Treemap zu machen, lass es mich wissen!Verwenden Sie die Ein-Klick-Funktion für ein Objekt tremaphapify in R Shiny
global.R
library(tidyverse)
library(treemapify)
library(shiny)
source("functions.R")
mt <- data.frame(mtcars)
cylinders <- unique(mt$cyl)
functions.R
tmapData <- function(act_cyl) {
play <- mt %>%
mutate(name = row.names(mtcars)) %>%
dplyr::filter(cyl == act_cyl)
return(play)
}
tmapPlot <- function(act_cyl) {
play <- tmapData(act_cyl)
p <- ggplot(play, aes(area = wt, fill = mpg, label = name)) +
geom_treemap() +
geom_treemap_text(grow = FALSE, reflow = TRUE, color = "black")
return(p)
}
server.R
shinyServer(function(input, output) {
active_cyl <- reactive({
input$cyl_input
})
output$tmap <- renderPlot({
tmapPlot(active_cyl())
})
output$tdata <- DT::renderDataTable(
out <- DT::datatable({
tmapData(active_cyl()) %>%
select(name, mpg, wt)
})
)
output$out_text <- renderPrint({
nearPoints(mt, input$tClick, threshold = 10,
maxpoints = 1, addDist = TRUE)
})
})
ui.R
Thanks so much! Alles, was du gesagt hast, ergibt Sinn. Muss dies in die eigentliche App umwandeln! –