0
我有以下代碼片段作爲閃亮應用程序的輸入。讓兩個圖表在一個閃亮的應用程序上浮動彼此
server.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")))
)
))
這一切工作,但是當我跑我閃亮的應用程序現在我得到彼此相鄰的兩個圖形。而實際上我想把它們放在彼此之上。有關我如何以最佳方式做到這一點的想法?