我正在用閃亮的包進行第一次嘗試,它很棒。但是,像往常一樣,我面臨一些問題。我已經管理,遵循閃亮的教程和谷歌,顯示兩個不同的氣象站的不同情節,但都顯示相同的變量。從選擇列表到反應圖的R閃亮通過變量
我想添加其他輸入列表,從而有可能選擇哪個變種是要繪製。當試圖運行腳本時,它似乎運行時沒有任何錯誤,但沒有出現劇情,只是選擇了菜單。
也許在將變量傳遞給server.R時出現錯誤,所以輸出oblima圖不能正確構建,只是猜測。試圖創建函數的一般方式,取決於輸入工作瓦爾但我失去了一些東西,也許有關反應,也許正確地傳遞瓦爾...
這些是ui.R
library("shiny")
shinyUI(pageWithSidebar(
headerPanel('Comparación de zonas - Temperatura'),
sidebarPanel(
selectInput("panel1", "Zona:",
list("Zona 1" = "1",
"Zona 2" = "2",
"Zona 3" = "3",
"Zona 4" = "4")),
selectInput("panel2", "Zona:",
list("Zona 1" = "1",
"Zona 2" = "2",
"Zona 3" = "3",
"Zona 4" = "4")),
selectInput("var", "Variable:",
list("tempc" = "tempc",
"relhum" = "relhum")),
helpText('Al seleccionar la zona se crearán automáticamente
el gráfico de evolución temporal.')
),
mainPanel(
conditionalPanel(condition = "inputId == 'panel1'",plotOutput('myplot')
),
conditionalPanel(condition = "inputId == 'panel2'",plotOutput("myplot")
)
)
))
代碼和server.R
library(shiny)
library(plyr)
library(ggplot2)
shinyServer(function(input, output) {
formulaText <- reactive(function() {
paste("Gràfica de ggplot: Zona ", input$zona1)
})
# Return the formula text for printing as a caption
output$caption <- reactiveText(function() {
formulaText()
})
# datasets
datos=read.table("data.dat",header=T)
data=as.data.frame(datos)
data=within(data, datetime <- as.POSIXct(paste(date, time),format = "%Y%m%d %H%M%S"))
rams <- reactive({
subset(data,data$stat_id %in% places$stat_id[places$Zona == input$panel1])
})
plot <- function(var) {
p <- ggplot(rams(),aes(x=datetime, y=var, colour=as.character(stat_id))) +
geom_line()
}
plot=p(input$var)
if(input$var == "tempc") {
plot <- plot + ylab("Temperatura (ºC)") + xlab(" ") +
ggtitle(gtitol) + theme(legend.title=element_blank()) + theme(legend.position="bottom") +
scale_y_continuous(limits = c(-20,ylim),breaks=c(seq(-20,ylim,by=2))) }
if (input$var == "relhum") {
plot <- plot +
ylab("Humedad relativa (%)") + xlab(" ") +
ggtitle(gtitol) + theme(legend.title=element_blank()) + theme(legend.position="bottom") +
scale_y_continuous(limits = c(0,100),breaks=c(seq(0,100,by=5))) }
output$myplot <- reactivePlot(function() {
print(plot)
})
})
預先感謝您的幫助和建議
'情節= P(輸入$ var)'是錯的 –
是的,但這不是唯一的問題。請參閱下面的答案。謝謝。 – pacomet
很高興知道'aes_string()',比你張貼這個答案。 –