我正在创建一个闪亮的应用程序,我想使用
brush
功能。该应用程序目前看起来像:
在哪里
box()
我明白了
Error: argument 1 is not a vector
当用户对绘图进行刷选时,此错误消失。
我如何将错误隐藏为更用户友好的描述,例如“请选择上述绘图的一个区域以生成此窗口…”。
情节
盒子()
应该绘制用户选择,例如绘图的放大版本。
代码:
data <- mtcars
library(shiny)
library(shinydashboard)
header <- dashboardHeader(title = "My Dashboard")
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem(text = "Main Menu", tabName = "MainPage")
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "MainPage",
fluidRow(
box(
width = 12,
plotOutput("myPlot1", brush = "userSelectedSummaryStatistics")
)
),
fluidRow(
box(
width = 4,
DT::dataTableOutput("userDefinedTable")
),
box(
width = 8,
plotlyOutput("selectedUserDataFromUserDefinedTable")
)
)
)
)
)
ui <- dashboardPage(
header, sidebar, body
)
server <- function(input, output, session){
output$myPlot1 <- renderPlot({
data %>%
ggplot(aes(x = mpg, y = disp)) +
geom_line()
})
selectedUserData = reactive({
userSelectedSummaryStatistics = input$userSelectedSummaryStatistics
userSelection = brushedPoints(data, userSelectedSummaryStatistics)
return(userSelection)
})
output$userDefinedTable = DT::renderDataTable(DT::datatable(selectedUserData()))
output$selectedUserDataFromUserDefinedTable <- renderPlotly({
ggplotly(
selectedUserData() %>%
ggplot(aes(x = mpg, y = disp)) +
geom_line()
)
})
}
shinyApp(ui, server)