更新:最初我试图使用plotly&ggplot与shinydashboard,但后来放弃了ggplot。我正在尝试分配hoverinfo数据,但是,我现在得到一个错误。“警告:错误:Tibble列必须具有兼容的大小。
- 大小0:列
x
、y
和color
。 - 尺寸2:色谱柱
text
。i只回收大小为1的值。一百一十四:”
下面是我的尝试。
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)
1条答案
按热度按时间b1uwtaje1#
整个
text=
参数需要是一个公式。~
不只是表示数据列名,它是用于未计算的表达式。因此,一个合适的工作示例应该如下所示当您尝试使用
color =~Petal.Length
并且只有一个点要绘制时,似乎确实存在问题。似乎由于某种原因,这些事件的组合禁用了悬停文本。这可能是一个bug。