R闪亮:散点图未显示

时间:2020-03-31 22:15:01

标签: r shiny r-plotly

我正在尝试基于动态滑块绘制plot_ly散点图。但是,似乎我缺少了一些东西。

运行应用程序时,出现的错误如下:

错误:无效的第一个参数

非常感谢您在理解问题方面的帮助。

请在下面的代码中查找(希望它现在可以重现了)。

#load libraries to be used. Pacman ensures library reproducibility 
if (!require("pacman")) install.package("pacman")
pacman::p_load(ggplot2,dplyr,tidyr, rpart, shiny, shinydashboard, plotly, DT)


#load Titanic dataset 
dataset<-read.csv(".../titanic.csv")


ui <- fluidPage(
  dashboardHeader(
    title = "My trial",
    titleWidth = 300
  ),

  dashboardSidebar(
    sidebarMenu(
      sidebarMenu(
        menuItem("Visualization", tabName = "visualization", icon = icon("dashboard")),
        menuItem("Data Table", tabName = "datatable", icon = icon("th"))
      )

    )
  ),

  dashboardBody(
    tabItems(
      # Content of first tab
      tabItem(tabName = "visualization",
              h2("Visualization using Plot_ly"),
              fluidRow(
                box(plotlyOutput("Trialplot")),
                box(
                  title = "Age range",
                  status="primary",
                  solidHeader=TRUE,
                  collapsible=TRUE,
                  sliderInput("slider", "Please select the age range to be seen:", 0, max(dataset$Age), c(0,max(dataset$Age)/2), ticks=FALSE)
                )
              ), 
              box(plotlyOutput("Trialplot"))

      ),

      # Content of second tab
      tabItem(tabName = "datatable",
              h2("Data table")
      )
    )
  )
)


server = shinyServer(function(input, output,session) { 



  output$Trialplot<-renderPlotly({
    dataset_filtered<-dataset[dataset$Age ==input$slider,]
    plot_ly(data = dataset_filtered, x = ~Fare, y = ~get(input$slider) , 
                                  color=~Survived, 
                                  colors=pal, 
                                  type='scatter',
                                  marker=list(size=10),
                                  hoverinfo='text',
                                  text=~paste("Name:",Name,", Age:",Age,", Fare",Fare)
                                  )%>%
                                  layout(title="Age vs.Fare")})

}
)

shinyApp(ui,server)

谢谢。

1 个答案:

答案 0 :(得分:1)

您不应在闪亮的应用程序中两次调用feign.hystrix.enabled=true,而且plotlyOutput("Trialplot")的两个值分别是滑块的最小值和最大值,因此不能使用这样的sliderInput:< / p>

我试图重现您的代码,现在它对我有用,下一次尝试发布带有dataset$Age == input$slider函数输出的数据。

dput(data)