我希望有一个使用ggiraph的交互式绘图,其中我的onclick启动了一个模式,这是一个弹出窗口,显示与我所单击的单个数据点相关的信息。
下面是我的代码。我无法使模式弹出窗口正常工作。我可以让一个Modal弹出窗口出现,但它是空白的。但是,我可以使用这里提供的一个示例让表自己进行过滤。
https://davidgohel.github.io/ggiraph/articles/offcran/shiny.html
'run_girafe_example("DT")‘
我想让这个过滤表出现在一个模态弹出窗口中。可能会将数据转置,并以更好的格式呈现。但是,如果我可以将数据呈现在Modal中,我就可以在以后弄清楚如何表示它。我只需要弄清楚如何让Modal显示过滤后的数据表!
如有任何帮助,我们将不胜感激:)
library(ggiraph)
library(ggplot2)
library(tidyverse)
library(htmltools)
library(DT)
library(shinyBS)
library(shinydashboard)
theme_set(theme_minimal())
data <- mtcars
ui <- fluidPage(
fluidRow(
column(width=12,
h4("click a point, the data table will be filtered...")
)
),
fluidRow(
column(width=12,
ggiraphOutput("fixedplot")
)
)
,
fluidRow(
column(width=12,
includeScript(path = "set_search_val.js"),
DT::dataTableOutput("modaltable")
)
)
)
server <- function(input, output, session) {
output$fixedplot <-renderGirafe({
data$label <- gsub(pattern = "'", " ", row.names(data) )
data$onclick <- paste0("set_search_val(\"", data$label, "\");")
gg <- ggplot(data = data,
mapping = aes(x=wt, y=mpg,
tooltip = label,
data_id = label,
onclick = onclick
)
) +
geom_point_interactive()
girafe(code = print (gg),
options = list(
opts_selection(type = "single")
)
)
})
observeEvent(input$fixedplot_selected,{
showModal(modalDialog(
tags$caption("Table"),
tableOutput("modaltable")
))
}
)
output$modaltable <- DT::renderDataTable({
car_data <- data[,1:7]
DT::datatable(car_data, escape = FALSE)
})
}
shinyApp(ui = ui, server = server)发布于 2020-02-28 14:59:56
您需要在modalDialog内部调用DT::renderDataTable:
library(ggiraph)
library(ggplot2)
library(tidyverse)
library(htmltools)
library(DT)
library(shinyBS)
library(shinydashboard)
theme_set(theme_minimal())
data <- mtcars
ui <- fluidPage(
fluidRow(
column(width=12,
h4("click a point, the data table will be filtered...")
)
),
fluidRow(
column(width=12,
ggiraphOutput("fixedplot")
)
)
,
fluidRow(
column(width=12,
includeScript(path = "set_search_val.js"),
DT::dataTableOutput("modaltable")
)
)
)
server <- function(input, output, session) {
output$fixedplot <-renderGirafe({
data$label <- gsub(pattern = "'", " ", row.names(data) )
data$onclick <- paste0("set_search_val(\"", data$label, "\");")
gg <- ggplot(data = data,
mapping = aes(x=wt, y=mpg,
tooltip = label,
data_id = label,
onclick = onclick
)
) +
geom_point_interactive()
girafe(code = print (gg),
options = list(
opts_selection(type = "single")
)
)
})
observeEvent(input$fixedplot_selected,{
showModal(modalDialog(
tags$caption("Table"),
DT::renderDataTable({
car_data <- data[,1:7]
DT::datatable(car_data, escape = FALSE)
})
))
}
)
output$modaltable <- DT::renderDataTable({
car_data <- data[,1:7]
DT::datatable(car_data, escape = FALSE)
})
}
shinyApp(ui = ui, server = server)https://stackoverflow.com/questions/60445453
复制相似问题