2015-09-11 62 views
2

我已經寫了一個R閃亮的應用程序,之前只有一個按鈕被點擊後才顯示一個圖。由於某種奇怪的原因,我不能得到下面的代碼,在點擊按鈕後輸入renderPlot函數(即單擊按鈕時永遠不會到達browser()),我很難過。請成爲我的第二雙眼睛,我確信我錯過了一些微不足道的東西。R Shiny - plotOutput內聯和大小參數可以防止輸入渲染圖

observe功能正常工作,並更新selectizeInput就像我想要的。導入csv也可以正常工作,我也可以使用DT::renderDataTable來顯示它。

您可以使用this爲例的數據,但它不應該的問題,因爲我的代碼沒有繪製任何東西

服務器

rm(list = ls()) 

library(shiny) 
library(leaflet) 
library(DT) 
library(stringr) 
library(zoo) 
options(shiny.maxRequestSize=30*1024^2) 

TAG_COL <- 1 
TIME_COL <- 2 
DATE_COL <- 3 
ACTION_COL <- 4 

HEADFIX_STR <- 'reward0' 

shinyServer(function(input, output, clientData, session) {  
    inFile<-reactive({ 
    input$file1 
    if(is.null(input$file1)){ 
     return(NULL) 
    } 
    else{ 
     inF<-read.csv(input$file1$datapath, header=input$header, sep=input$sep, quote=input$quote) 
     inF 
    } 
    }) 

    observe({ 
    if(!is.null(inFile)){ 
     updateSelectizeInput(session, "tagChooser", 
          'Choose Tags to plot', 
          choices = unique(inFile()[[TAG_COL]])) 
    } 
    }) 

    # Subset between start and end with bin column and selected mice 
    subsetTable<-reactive({ 
    browser() 
    # More code to come 
    }) 

    # Plot histrogram of times between headfixes 
    # TODO: assumes all mice in same cage. Fix to make it work for a selection of mice from seperate cages 
    output$plotHist<-renderPlot({ 
    input$goButton 
    browser() # <-- Why is this browser() never reached after clicking the button? 
    isolate({ 
     subsetTable() 
     subsetHeadfixes<-subsetTable() 
     # More code to come 
     }) 
    }) 
}) 

UI

rm(list = ls()) 
# Immediately enter the browser/some function when an error occurs 
# options(error = some funcion) 

library(shiny) 
library(DT) 

shinyUI(fluidPage(
    titlePanel("MurphyLab"), 
    sidebarLayout(
    sidebarPanel(
     fileInput('file1', 'Choose CSV File', 
       accept=c('text/csv', 
         'text/comma-separated-values,text/plain', 
         '.csv')), 
     checkboxInput('header', 'Header', TRUE), 
     radioButtons('sep', 'Separator', 
        c(Comma=',', 
        Semicolon=';', 
        Tab='\t'), 
        ','), 
     radioButtons('quote', 'Quote', 
        c(None='', 
        'Double Quote'='"', 
        'Single Quote'="'"), 
        '"'), 
     selectizeInput('tagChooser', 'Choose Tags to plot', choices = c("data not loaded"), multiple = TRUE), 
     textInput("abs_start","Insert start date and time. Format: %Y-%m-%d %H:%M:%S",value="2015-06-15 01:00:00"), 
     textInput("abs_end","Insert end date and time. Format: %Y-%m-%d %H:%M:%S",value="2015-08-15 01:00:00"), 
     textInput("binning", "Binning in seconds",value = 86400), 
     actionButton("goButton", "Plot") 
    ), 

    mainPanel(
     plotOutput("plotHist", inline = TRUE,width='auto',height='auto') 
    ) 
) 
) 
) 

UPDATE:

因此,當我在012中更改plotOutput呼叫到plotOutput("plotHist")一切按預期工作。我正在改變我的問題,而不是:爲什麼這會解決問題?此外,只有inline設置爲FALSE不能解決問題。

的文檔inline狀態:

使用內聯(跨度())或塊容器(DIV()),用於輸出

回答

1

renderPlot()文檔(I強調培訓相關下面部分):

widthheight渲染曲線的寬度/高度,以像素爲單位;或'auto'來使用綁定到該圖的HTML元素的offsetWidth/offsetHeight。你也可以傳入一個函數,返回寬度/高度像素或'自動';在函數的主體中,您可以引用被動值和函數。 渲染內聯圖時,必須提供寬度和高度的數值(以像素爲單位)。