Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有一种方法可以使用ggiraph和onclick在R中的模式窗口中显示过滤后的数据表?_R_Shiny_Onclick_Modal Dialog_Ggiraph - Fatal编程技术网

有没有一种方法可以使用ggiraph和onclick在R中的模式窗口中显示过滤后的数据表?

有没有一种方法可以使用ggiraph和onclick在R中的模式窗口中显示过滤后的数据表?,r,shiny,onclick,modal-dialog,ggiraph,R,Shiny,Onclick,Modal Dialog,Ggiraph,我希望使用ggiraph创建一个交互式绘图,其中我的onclick启动一个模式,该模式是一个弹出窗口,显示与我单击的单个数据点相关的信息 下面是我的代码。我无法使模式弹出窗口正常工作。我可以得到一个模态弹出窗口,但它是空白的。但是,我可以使用这里提供的一个示例让表进行自我过滤 “run_girafe_示例(“DT”)” 我想要的是在一个模式弹出窗口中显示这个过滤过的表。可能是数据被转换并以更好的格式呈现。但是,如果我能得到模型中要显示的数据,我可以在以后找出如何表示它。我只需要弄清楚如何让模态

我希望使用ggiraph创建一个交互式绘图,其中我的onclick启动一个模式,该模式是一个弹出窗口,显示与我单击的单个数据点相关的信息

下面是我的代码。我无法使模式弹出窗口正常工作。我可以得到一个模态弹出窗口,但它是空白的。但是,我可以使用这里提供的一个示例让表进行自我过滤

“run_girafe_示例(“DT”)”

我想要的是在一个模式弹出窗口中显示这个过滤过的表。可能是数据被转换并以更好的格式呈现。但是,如果我能得到模型中要显示的数据,我可以在以后找出如何表示它。我只需要弄清楚如何让模态首先显示过滤后的数据表

任何帮助都将不胜感激:)

库(ggiraph)
图书馆(GG2)
图书馆(tidyverse)
图书馆(htmltools)
图书馆(DT)
图书馆(shinyBS)
图书馆(shinydashboard)
theme\u集(theme\u minimal())

数据您需要调用
DT::renderDataTable
内部
modalDialog
调用:

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)

库(ggiraph)
图书馆(GG2)
图书馆(tidyverse)
图书馆(htmltools)
图书馆(DT)
图书馆(shinyBS)
图书馆(shinydashboard)
theme\u集(theme\u minimal())

非常感谢您的帮助!这允许显示表格,但是过滤不再工作,并显示整个表格。我只希望在单击某个点时显示过滤后的数据。我今天会把它弄得乱七八糟,看看能不能让它发挥作用。谢谢你帮我找到了正确的方向!我实际上需要做的是更改set_search_val.js文件,使其不只是对表应用搜索功能。我需要onclick函数来启动一个全新页面的创建,该页面根据我单击的数据点从data.frame中提取数据。是的,这只是一个简单的示例:),您可以使用服务器方法而不是仅使用客户端。有很多选择。如果您不知道js编码,我建议您只使用服务器方法
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)