闪亮的应用程序:brushOpts在输入$ plot1_brush上返回/获取“ Null”

时间:2019-03-06 02:07:43

标签: r shiny shiny-server shiny-reactivity shinyapps

我正在尝试开发一个基于tabPanel的应用程序来演示我的研究。我正在尝试打印散点图,并试图使用画笔从中选择数据的子集。但是,从ggplot2中选择值时,我无法检索坐标。根据我的理解,该错误是由于

  

input $ plot1_brush

返回“ NULL”

我在这里发布服务器代码和用户界面。

预先感谢您的帮助。

  

Server.R

library(shiny)

shinyServer(function(input, output) {

library(plotly)
library(igraph)


# l is defined here 
output$distPlot <- renderPlotly(plot_ly(as.data.frame(l), x=l[,1], y = l[,2], z = l[,3], type = 'scatter3d' ))

## Tab 2 ##
# Works Fine

output$test <- renderDataTable({
  library(kableExtra)
  library(DT)
  library(Cairo)

  file_reader <- read.csv(file = "./data/output.txt", header = FALSE)
  transpose_step1 <- melt(file_reader)
  transpose_table <- as.data.frame(transpose_step1$value)
  colnames(transpose_table) <- c("Traffic")
  transpose_table$col2 <- cbind(c(1:length(transpose_table$Traffic)))
  datatable(transpose_table, filter = 'top', options = list(pageLength = 5))
})

##### Tab 3 ######    
# ERROR IS MOST LIKELY HERE

library(Cairo)
library(ggplot2)
mtcars2 <- mtcars[, c("mpg", "cyl", "disp", "hp", "wt", "am", "gear")]
output$plot2 <- renderPlot({
  ggplot(mtcars2, aes(wt, mpg)) + geom_point()
})

output$brush_info <- renderPrint({
  #print(input$plot2)       # THIS IS NULL
  #print(input$plot1_click) # THIS IS NULL
  #brushedPoints(mtcars2, input$plot1_brush) # THIS IS NULL
  input$plot1_brush
})

})
  

UI.R

library(shiny)
library(plotly)

shinyUI(navbarPage("Network Visualization",

# Application title
tabPanel("Visualization",

  # Sidebar with a slider input for number of bins
  sidebarLayout(
      sidebarPanel(
          selectInput(inputId = "type",
                      label = "Type of Graph",
                      choices = c("Rene Erdos","P2P-Gnutella"),
                      selected = "P2P-Gnutella"),
          selectInput(inputId = "color",
                      label = "Type of Color",
                      choices = c("Red","Green"),
                      selected = "Red"),
          submitButton(text = "Apply Changes", icon = NULL, width = NULL)
      ),


      # Show a plot of the generated distribution
      mainPanel(
      plotlyOutput("distPlot")
      ))
),
tabPanel("Traffic",
          dataTableOutput("test")
),
tabPanel("Interactive",
          plotOutput("plot2", height = 300,
                     # outputId = 'please',
                      # clickId = "plot1_click",
                        brush = brushOpts(
                          id = "plot1_brush")),
            fluidRow(
              column(width = 12,
                     h4("Selected Flows"),
                     verbatimTextOutput("brush_info")
              )
            )
)
))

在这里您可以看到 input $ plot1_brush 应该向我返回画笔坐标,但是它始终为 NULL ,并且我认为输入无法达到 plot1_brush

注意:,如果我将UI和服务器作为单个应用程序/选项卡,则会得到坐标。

非常感谢您的帮助!

0 个答案:

没有答案