2016-01-20 40 views
1

我有兩個問題需要解決。首先,模型不運行,我不知道爲什麼?如何在sidebarPanel中顯示沒有空白區域的情節?

DONE!by Vongo and NicE。第一個問題是:我有兩個地點和他們的銷售數量顯示爲情節。我想根據ggtitle(「分析輸入$位置」)等選擇輸入來更改劇情標題。

其次,我想顯示在sidebarPanel中的圖 - 在執行buton-下面。然而,在演習中,我有一個白色的空白區域,已經預定了要製作的地塊。在執行繪圖之前,我不希望在sidebarPanel中有這個預訂區域。

enter image description here

ui.r 

library(shiny) 
shinyUI(pageWithSidebar(
headerPanel("Sidebar Study"), 
sidebarPanel(

selectInput(inputId = "location",label = "Choose Location", 
      choices = c('Los Angeles', 'New York', selected = "Los Angeles"), 

actionButton("execute","Execute") 
plotOutput("plot"))), 
    mainPanel())) 


server.r 

library(shiny) 

shinyServer(function(input, output,session) { 

    output$plot <- renderPlot({ 
    if(input$execute){ 
    if(input$location="New York"){ 
    tmp <- data.frame(time = 1:100, sales = round(runif(100, 150, 879))) 
    } 
    if(input$location="Los Angeles"){ 
    tmp <- data.frame(time = 1:100, sales = round(runif(100, 90, 512))) } 
    y<-ggplot(as.data.frame(tmp), aes(time)) + geom_line(size=1,aes(y=sales, colour = "sales"))+ ggtitle(paste("Analyze of", input$location)) 
    y 
}}) 
}) 
+0

對於你的第一個問題,我只是讀得很快,但是'ggtitle(paste(「Analyze of」,input $ location))''呢? (也許我讀得太快) – Vongo

+0

是的,你是對的謝謝! –

回答

2

您可以使用renderUiuiOutput動態地添加持有人的情節,當用戶點擊該按鈕。在你ui.R,嘗試更換plotOutput("plot")通過uiOutput("plotDiv")並在server.R您可以添加:

output$plotDiv <- renderUI({ 
    if(input$execute>0){ 
    plotOutput("plot") 
    } 
    }) 

對於情節的標題,你可以這樣做:

ggtitle(paste("Analyze of",input$location)) 

你也有問題與ifserver.R,它應該是input$location=="New York"(添加一個等號)。您在ui.R中也有括號問題,此時操作按鈕和繪圖輸出位於selectInput中。

+0

您對ggtitle的建議效果很好。謝謝! –

相關問題