我有一些問題,實施GGPLOT2成閃亮的應用qqplot閃亮的應用改變軸和問題,有條件的情節
我不能得到的代碼在我下面給的例子工作。由於某種原因,當我使用
aes_string
時,它找不到factor1
,當我使用aes
時,它找不到params()
。在文件中,用我的數據提供,這一步工作。對不起。我想用qqplot2繪製我的 項目的數據。當我拿出數據並在閃亮的應用程序外繪製它們時,一切都很好。當我在 的代碼中使用閃亮的應用程序時,它將我的座標軸從因子 更改爲有爭議的座標。
我正在根據用戶輸入和「radioButtons」在x軸上更改 上的因子。當我 使用stripchart()時,它完美地工作。當我使用ggplot代替它時, 首先正常工作,但是當我更改因子(更改radioButton的值)時,它找不到輸入對象(
input$strain
)。
對不起,很長的文章。非常感激你的幫助。
這裏是我的代碼:
ui.R
library(shiny)
# Define UI for dataset viewer application
ui<-(fluidPage(
titlePanel("My project"),
sidebarLayout(
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("exp1","exp2", "exp3"),selected="exp1"),
selectInput(inputId = "param",choices = c("Repsonse A","Response B"),label = "Choose repsonse",selected="Repsonse A"),
selectInput("factors", "Choose grouping factor:",
choices = c("No grouping","Block"),selected="No grouping"),
radioButtons(inputId = "fac",choice=c("factor1 on x-axis","factor2 on x-axis"), "Choose type of x-axis")
),
mainPanel(
h3(textOutput("caption", container = span)),
plotOutput("strip")
)
)
))
和 server.R
library(shiny)
library(datasets)
library(ggplot2)
server<-(function(input, output,clientData, session) {
df<-data.frame("respondA"=runif(20, min=0, max=0.4),"respondB"=runif(20, min=0, max=0.4),"factor1"="A","factor2"="B","replicate"=as.factor(c(1:20)))
df2<-data.frame("respondA"=runif(20, min=0, max=0.4),"respondB"=runif(20, min=0, max=0.4),"factor1"="A","factor2"="B","replicate"=as.factor(c(1:20)))
df3<-data.frame("respondA"=runif(20, min=0, max=0.4),"respondB"=runif(20, min=0, max=0.4),"factor1"="A","factor2"="B","replicate"=as.factor(c(1:20)))
datasetInput <- reactive({
switch(input$dataset,
"exp1" = df,
"exp2" = df2,
"exp3" = df3)
})
params <- reactive({
switch(input$param,
"Repsonse A" = datasetInput()$respondA,
"Response B" = datasetInput()$respondB)
})
factor <- reactive({
switch(input$factors,
"No grouping"=NULL,
"Block" = "replicate")
})
output$strip <- renderPlot({
if (input$fac == "factor1 on x-axis") {
p<-ggplot(datasetInput(), aes_string(x = factor1, y = params())) +
ylab("Mylabel1")+
xlab("Mylabel2")+
geom_jitter(position = position_jitter(width = .2),shape=19,size=5,aes_string(colour = factor()))+
labs(title = "Mytitle")+
theme_bw() +
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank())
print(p)
} else if(input$fac == "factor2 on x-axis") {
q<-ggplot(datasetInput(), aes_string(x = factor2, y = params())) +
ylab("Mylabel1")+
xlab("Mylabel2")+
geom_jitter(position = position_jitter(width = .2),shape=19,size=5,aes_string(colour = factor()))+
labs(title = "Mytitle")+
theme_bw() +
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank())
print(q)
}
})
})
shinyApp(ui=ui,server=server)
PS:我想用ggplot,因爲我可以改變顏色基於一個因素的數據非常容易。對於一些因素,我有> 20個因子水平,並且它不適用於stripchart()
和add=T
有時候...你應該停止工作,並思考別的東西。對不起 – Mugel2110
不用擔心!幸運的是有一個快速修復 –