【问题标题】:Let two charts float above each other in a shiny application让两个图表在闪亮的应用程序中浮动
【发布时间】:2016-07-21 09:30:26
【问题描述】:

我有以下代码 sn-ps 作为闪亮应用程序的输入。

服务器.R

library(shiny)
library(ggplot2)

#df_filter <- df2[df2$month == input$var,]

shinyServer(function(input, output){

  #Hier output je je plot, let op $myhist is iets wat je teruggeeft
  output$myhist1 <- renderPlot({

    gg <- ggplot(data = df2, aes(x=names, y = number, fill = kind)) + geom_bar(stat="identity") + coord_flip()
    ggg <- gg + ylim(0,1) + theme(legend.position="left") + xlab("")

    plot(ggg, height = 100, width = 100)

  })

  output$myhist2 <- renderPlot({


    p <- ggplot(data = df3, aes(x=names2, y = number2, group = 1 )) + geom_point(size=3, fill="white") 
    pp <- p + xlab("Month") + ylab("Mentioned in job ads") + ggtitle("Demand for R") + geom_line()
    ppp <- pp + geom_point(aes(x = names2, y = benchmark), colour="red", size = 3) + geom_line(aes(x = names2, y = benchmark), colour = "red") 

    plot(ppp)

  })

})

UI.R

library(shiny)
shinyUI(fluidPage(

  #sample data 1
  names <- c("R", "Python", "Qlikview", "R", "Python", "Qlikview"),
  number <- c(0.4, 0.8, 0.3, 0.3, 0.7, 0.2),
  kind <- c("Programming", "Programming", "Dashboarding","Programming", "Programming", "Dashboarding"),
  month <- c(1,2,3,1,2,3),
  df2 <- data.frame(names, number, kind, month),

  #sample data 2
  names2 <- c(1,2,3,4,5,6,7,8,9,10,11,12),
  names2 <- as.factor(names2),
  number2 <- c(0.33, 0.28, 0.32, 0.23, 0.34, 0.45, 0.32, 0.4, 0.5, 0.6, 0.61, 0.59),
  benchmark <- c(0.33, 0.28, 0.32, 0.23, 0.34, 0.45, 0.36, 0.5, 0.7, 0.67, 0.69, 0.89),
  df3 <- data.frame(names2, number2, benchmark),

  #outlinen title
  titlePanel(title = "227 panel"),
  sidebarLayout(
    sidebarPanel(

      #Here you enter the var that you would like to use to filter the data shown in the graph
      selectInput("var", "Select the month", choices = month),
      br(),
      br(),
      br(),
      br(),
      br(),
      br(),
      br(),
      br(),
      br(),
      br(),
      br(),
      br(),
      selectInput("var", "Select the month", choices = month),
      br(),
      br(),
      br(),
      br(),
      br(),
      br()
    ),

    mainPanel((""),
              splitLayout(cellHeights = c("50%", "50%"), plotOutput("myhist1"), plotOutput("myhist2")))
  )
)) 

这一切都有效,但是当我现在运行我闪亮的应用程序时,我得到了两个相邻的图表。虽然实际上我想让它们漂浮在彼此之上。关于如何以最佳方式做到这一点的任何想法?

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    splitLayout(cellHeights = c("50%", "50%") 会使它们彼此相邻出现。 简单的

    mainPanel(
         plotOutput("myhist1"),
         plotOutput("myhist2")
      )
    

    应该给你你正在寻找的东西。 通过浮动在彼此之上,我希望您只是指页面上的一个图,并且当您滚动时,页面上的下一个图。 (而不是一个情节叠加/叠加在另一个上)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-08
      • 2021-11-27
      • 1970-01-01
      • 2018-12-29
      • 1970-01-01
      • 2014-04-11
      • 2014-03-26
      • 1970-01-01
      相关资源
      最近更新 更多