我有以下代码片段作为闪亮应用程序的输入。
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)
})
})
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")))
)
))
这一切都有效,但是当我运行我的闪亮应用程序时,我会将两个图形彼此相邻。实际上我想把它们放在彼此之上。关于如何以最佳方式做到这一点的任何想法?
答案 0 :(得分:0)
splitLayout(cellHeights = c("50%", "50%")
会使它们彼此相邻。
简单
mainPanel(
plotOutput("myhist1"),
plotOutput("myhist2")
)
应该给你你想要的东西。 通过互相浮动,我希望你的意思只是页面上的一个情节,当你滚动时,页面上的下一个情节。 (而不是一个图叠加/叠加在另一个上)