【问题标题】:How can I display a plot in sidebarPanel without blank area?如何在没有空白区域的 sidebarPanel 中显示绘图?
【发布时间】:2016-01-20 13:44:16
【问题描述】:

我有两个问题要解决。首先,模型没有运行我不知道为什么?

DONE!,作者:Vongo 和 Nice。第一个问题是:我有两个位置,它们的销售数量显示为情节。我想根据像 ggtitle("Analyze of input$location") 这样的选择输入来更改绘图标题。

其次,我想在侧边栏面板中显示绘图 - 在执行按钮下方 -。然而,在练习中,我有一个白色的空白区域,已经预订了要制作的地块。在执行情节之前,我不想在侧边栏面板中有这个预订区域。

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
}})
})

【问题讨论】:

  • 对于你的第一个问题,我读得很快,但是ggtitle(paste("Analyze of",input$location)) 呢? (可能是我读得太快了)
  • 是的,谢谢!

标签: r plot ggplot2 shiny


【解决方案1】:

您可以使用renderUiuiOutput 在用户单击按钮时为绘图动态添加持有者。在您的 ui.R 中,尝试将 plotOutput("plot") 替换为 uiOutput("plotDiv") 并在 server.R 中添加:

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

对于情节的标题,你可以这样做:

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

您还对server.R 中的if 有疑问,它应该是input$location=="New York"(添加等号)。您的ui.R 中也有括号问题,现在操作按钮和绘图输出在 selectInput 中。

【讨论】:

    猜你喜欢
    • 2011-08-19
    • 1970-01-01
    • 2020-03-29
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多