"Warning: Error in : Tibble columns must have compatible sizes." 将 hoverinfo 添加到过滤图时
"Warning: Error in : Tibble columns must have compatible sizes." when adding hoverinfo to filtered plot
更新:
最初我试图将 plotly&ggplot 与 shinydashboard 一起使用,但后来放弃了 ggplot。我正在尝试分配 hoverinfo 数据,但是我现在遇到错误。
“
警告:错误:Tibble 列必须具有兼容的大小。
- 大小 0:列
x
、y
和 color
。
- 大小 2:列
text
。
i 只有大小为 1 的值被回收。
114:
“
下面是我的尝试。
library(shinydashboard)
library(shinyWidgets)
library(shiny)
library(DT)
#______________________________________________________________________________#
server <- function(input, output, session) {
df <- reactive({
subset(iris, Petal.Width %in% input$Petalw)
})
# Extract list of Petal Lengths from selected data - to be used as a filter
p.lengths <- reactive({
unique(df()$Petal.Length)
})
# Filter based on Petal Length
output$PetalL <- renderUI({
pickerInput("PetalLengthSelector", "PetalLength", as.list(p.lengths()), options = list(`actions-box` = TRUE),multiple = T)
})
# Subset this data based on the values selected by user
df_1 <- reactive({
foo <- subset(df(), Petal.Length %in% input$PetalLengthSelector)
return(foo)
})
output$table <- DT::renderDataTable(
DT::datatable(df_1(), options = list(searching = FALSE,pageLength = 25))
)
output$correlation_plot <- renderPlotly({
plot1 <- plot_ly(data=df_1(),
x = ~Petal.Length,
y = ~Petal.Width,
type = 'scatter',
#mode ="lines+markers",
color =~Petal.Length,
text = paste("Sepal.Length:",~Sepal.Length,"<br>",
"Sepal.Width:",~Sepal.Width,"<br>",
"Petal.Length:",~Petal.Length,"<br>",
"Petal.Width:",~Petal.Width,"<br>",
"Species:",~Species),
hoverinfo = 'text'
)
})
}
#______________________________________________________________________________#
ui <- navbarPage(
title = 'Select values in two columns based on two inputs respectively',
fluidRow(
column(width = 12,
plotlyOutput('correlation_plot')
)
),
fluidRow(
column(width = 6,
pickerInput("Petalw","PetalWidth", choices = unique(iris$Petal.Width),selected = c("PetalWidth"), options = list(`actions-box` = TRUE),multiple = T)
),
column(width = 6,
uiOutput("PetalL")
)
),
fluidRow(
column(12,
tabPanel('Table', DT::dataTableOutput('table'))
)
)
)
shinyApp(ui, server)
整个text=
参数需要是一个公式。 ~
不仅表示数据列名称,还用于未计算的表达式。所以一个合适的工作示例应该看起来像
output$correlation_plot <- renderPlotly({
fig <- plot_ly(
data = df_1(),
x = ~Sepal.Length,
y = ~Sepal.Width,
type = 'scatter',
mode = 'markers',
text = ~paste("Sepal.Length:",Sepal.Length,"<br>",
"Sepal.Width:",Sepal.Width,"<br>",
"Petal.Length:",Petal.Length,"<br>",
"Petal.Width:",Petal.Width,"<br>",
"Species:",Species),
hoverinfo = 'text'
)
})
当您尝试使用 color =~Petal.Length
并且您只有一个点可以绘制时,似乎确实存在问题。由于某种原因,这种事件组合似乎禁用了悬停文本。这可能是一个错误。
更新: 最初我试图将 plotly&ggplot 与 shinydashboard 一起使用,但后来放弃了 ggplot。我正在尝试分配 hoverinfo 数据,但是我现在遇到错误。 “ 警告:错误:Tibble 列必须具有兼容的大小。
- 大小 0:列
x
、y
和color
。 - 大小 2:列
text
。 i 只有大小为 1 的值被回收。 114: “
下面是我的尝试。
library(shinydashboard)
library(shinyWidgets)
library(shiny)
library(DT)
#______________________________________________________________________________#
server <- function(input, output, session) {
df <- reactive({
subset(iris, Petal.Width %in% input$Petalw)
})
# Extract list of Petal Lengths from selected data - to be used as a filter
p.lengths <- reactive({
unique(df()$Petal.Length)
})
# Filter based on Petal Length
output$PetalL <- renderUI({
pickerInput("PetalLengthSelector", "PetalLength", as.list(p.lengths()), options = list(`actions-box` = TRUE),multiple = T)
})
# Subset this data based on the values selected by user
df_1 <- reactive({
foo <- subset(df(), Petal.Length %in% input$PetalLengthSelector)
return(foo)
})
output$table <- DT::renderDataTable(
DT::datatable(df_1(), options = list(searching = FALSE,pageLength = 25))
)
output$correlation_plot <- renderPlotly({
plot1 <- plot_ly(data=df_1(),
x = ~Petal.Length,
y = ~Petal.Width,
type = 'scatter',
#mode ="lines+markers",
color =~Petal.Length,
text = paste("Sepal.Length:",~Sepal.Length,"<br>",
"Sepal.Width:",~Sepal.Width,"<br>",
"Petal.Length:",~Petal.Length,"<br>",
"Petal.Width:",~Petal.Width,"<br>",
"Species:",~Species),
hoverinfo = 'text'
)
})
}
#______________________________________________________________________________#
ui <- navbarPage(
title = 'Select values in two columns based on two inputs respectively',
fluidRow(
column(width = 12,
plotlyOutput('correlation_plot')
)
),
fluidRow(
column(width = 6,
pickerInput("Petalw","PetalWidth", choices = unique(iris$Petal.Width),selected = c("PetalWidth"), options = list(`actions-box` = TRUE),multiple = T)
),
column(width = 6,
uiOutput("PetalL")
)
),
fluidRow(
column(12,
tabPanel('Table', DT::dataTableOutput('table'))
)
)
)
shinyApp(ui, server)
整个text=
参数需要是一个公式。 ~
不仅表示数据列名称,还用于未计算的表达式。所以一个合适的工作示例应该看起来像
output$correlation_plot <- renderPlotly({
fig <- plot_ly(
data = df_1(),
x = ~Sepal.Length,
y = ~Sepal.Width,
type = 'scatter',
mode = 'markers',
text = ~paste("Sepal.Length:",Sepal.Length,"<br>",
"Sepal.Width:",Sepal.Width,"<br>",
"Petal.Length:",Petal.Length,"<br>",
"Petal.Width:",Petal.Width,"<br>",
"Species:",Species),
hoverinfo = 'text'
)
})
当您尝试使用 color =~Petal.Length
并且您只有一个点可以绘制时,似乎确实存在问题。由于某种原因,这种事件组合似乎禁用了悬停文本。这可能是一个错误。