我正在尝试开发一个基于 tabPanel 的应用程序来展示我的研究。我正在尝试打印散点图并尝试使用画笔从中选择数据的子集。但是,在从 ggplot2 中选择值时,我无法检索坐标。据我了解,该错误源于以下事实
输入$plot1_brush
返回一个'NULL'
我在这里发布服务器代码和 UI。
在此先感谢您的帮助。
服务器.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
})
})
用户界面
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 和服务器作为单个应用程序/选项卡,我会得到坐标。
任何帮助深表感谢 !