Q: R plotly plot_ly function: axis titles don't appear when I call plotly inside a project I am using R3.4.0 and I am developing under RStudio in Windows 10 in the form of a project to produce a package.
I don't understand why the titles of the axes don't appear. I don't even have an error message.
Version 1:
#' TestPlotly
#' @export
#' @importFrom plotly plot_ly

TestPlotly=function()
{
  p<-plot_ly(x = 1:10, y = 1:10,xaxis=list(title="tr"),yaxis=list(title="ts"),type="scatter",mode="lines")
  print(p)
}


NB: I get the same problem with this code kindly suggested by somebody:
#' TestPlotly
#' @export
#' @importFrom plotly plot_ly

TestPlotly=function()
{
  plot_ly(x = 1:10, y = 1:10,type="scatter",mode="lines") %>%
    layout(
     xaxis = list(title="tr"),
     yaxis = list(title="ts")
   )
}

Important remark: When I'm outside of the project, it works. Why is this?
However I still need to have it working inside a project
> TestPlotly=function()
+ {
+     plot_ly(x = 1:10, y = 1:10,type="scatter",mode="lines") %>% 
+         layout(
+             xaxis = list(title="tr"),
+             yaxis = list(title="ts")
+         )
+     
+ }
> TestPlotly()


Let's go back to the package form. When I'm doing 
debugonce(plot_ly)

, when I call:    
 Browse[2]> print(attrs)

, I am obtaining among other things, this which seems correct:
$xaxis
$xaxis$title
[1] "tr"


$yaxis
$yaxis$title
[1] "ts"

Inside the debug of plot_ly, I am then debugging config, which is at the end of that function, and I still obtain the previous thing. I am showing to you what I obtain at the end of config, to me it seems all correct which is weird. 
        Browse[3]> print(p$dependencies)
        [[1]]
        List of 10
         $ name      : chr "typedarray"
         $ version   : chr "0.1"
         $ src       :List of 1
          ..$ file: chr "C:/Program Files/R/R-3.4.0/library/plotly/htmlwidgets/lib/typedarray"
         $ meta      : NULL
         $ script    : chr "typedarray.min.js"
         $ stylesheet: NULL
         $ head      : NULL
         $ attachment: NULL
         $ package   : NULL
         $ all_files : logi FALSE
         - attr(*, "class")= chr "html_dependency"

        [[2]]
        List of 10
         $ name      : chr "jquery"
         $ version   : chr "1.11.3"
         $ src       :List of 1
          ..$ file: chr "C:/Program Files/R/R-3.4.0/library/crosstalk/lib/jquery"
         $ meta      : NULL
         $ script    : chr "jquery.min.js"
         $ stylesheet: NULL
         $ head      : NULL
         $ attachment: NULL
         $ package   : NULL
         $ all_files : logi TRUE
         - attr(*, "class")= chr "html_dependency"

        [[3]]
        List of 10
         $ name      : chr "crosstalk"
         $ version   : chr "1.0.0"
         $ src       :List of 1
          ..$ file: chr "C:/Program Files/R/R-3.4.0/library/crosstalk/www"
         $ meta      : NULL
         $ script    : chr "js/crosstalk.min.js"
         $ stylesheet: chr "css/crosstalk.css"
         $ head      : NULL
         $ attachment: NULL
         $ package   : NULL
         $ all_files : logi TRUE
         - attr(*, "class")= chr "html_dependency"

        [[4]]
        List of 10
         $ name      : chr "plotly-htmlwidgets-css"
         $ version   : chr "1.39.2"
         $ src       :List of 1
          ..$ file: chr "C:/Program Files/R/R-3.4.0/library/plotly/htmlwidgets/lib/plotlyjs"
         $ meta      : NULL
         $ script    : NULL
         $ stylesheet: chr "plotly-htmlwidgets.css"
         $ head      : NULL
         $ attachment: NULL
         $ package   : NULL
         $ all_files : logi FALSE
         - attr(*, "class")= chr "html_dependency"

        [[5]]
        List of 10
         $ name      : chr "plotly-main"
         $ version   : chr "1.39.2"
         $ src       :List of 1
          ..$ file: chr "C:/Program Files/R/R-3.4.0/library/plotly/htmlwidgets/lib/plotlyjs"
         $ meta      : NULL
         $ script    : chr "plotly-latest.min.js"
         $ stylesheet: NULL
         $ head      : NULL
         $ attachment: NULL
         $ package   : NULL
         $ all_files : logi FALSE
         - attr(*, "class")= chr "html_dependency"

        Browse[3]> 
        debug: nms <- sapply(p$x$config[["modeBarButtonsToAdd"]], "[[", "name")
        Browse[3]> 
        debug: hasCollab <- sharingButton()[["name"]] %in% nms
        Browse[3]> 
        debug: if (collaborate && !hasCollab) {
            nAdd <- length(p$x$config[["modeBarButtonsToAdd"]])
            p$x$config[["modeBarButtonsToAdd"]][[nAdd + 1]] <- sharingButton()
        }
        Browse[3]> 
        debug: nAdd <- length(p$x$config[["modeBarButtonsToAdd"]])
        Browse[3]> 
        debug: p$x$config[["modeBarButtonsToAdd"]][[nAdd + 1]] <- sharingButton()
        Browse[3]> 
        debug: if (!collaborate) {
            p$x$config[["modeBarButtonsToAdd"]][nms %in% sharingButton()[["name"]]] <- NULL
        }
        Browse[3]> 
        debug: p$x$config$cloud <- cloud
        Browse[3]> 
        debug: p
        Browse[3]> print(x$config)
        Error in print(x$config) : object 'x' not found
        Browse[3]> print(p$x$config)
        $modeBarButtonsToAdd
        $modeBarButtonsToAdd[[1]]
        $modeBarButtonsToAdd[[1]]$name
        [1] "Collaborate"

        $modeBarButtonsToAdd[[1]]$icon
        $modeBarButtonsToAdd[[1]]$icon$width
        [1] 1000

        $modeBarButtonsToAdd[[1]]$icon$ascent
        [1] 500

        $modeBarButtonsToAdd[[1]]$icon$descent
        [1] -50

        $modeBarButtonsToAdd[[1]]$icon$path
        [1] "M487 375c7-10 9-23 5-36l-79-259c-3-12-11-23-22-31-11-8-22-12-35-12l-263 0c-15 0-29 5-43 15-13 10-23 23-28 37-5 13-5 25-1 37 0 0 0 3 1 7 1 5 1 8 1 11 0 2 0 4-1 6 0 3-1 5-1 6 1 2 2 4 3 6 1 2 2 4 4 6 2 3 4 5 5 7 5 7 9 16 13 26 4 10 7 19 9 26 0 2 0 5 0 9-1 4-1 6 0 8 0 2 2 5 4 8 3 3 5 5 5 7 4 6 8 15 12 26 4 11 7 19 7 26 1 1 0 4 0 9-1 4-1 7 0 8 1 2 3 5 6 8 4 4 6 6 6 7 4 5 8 13 13 24 4 11 7 20 7 28 1 1 0 4 0 7-1 3-1 6-1 7 0 2 1 4 3 6 1 1 3 4 5 6 2 3 3 5 5 6 1 2 3 5 4 9 2 3 3 7 5 10 1 3 2 6 4 10 2 4 4 7 6 9 2 3 4 5 7 7 3 2 7 3 11 3 3 0 8 0 13-1l0-1c7 2 12 2 14 2l218 0c14 0 25-5 32-16 8-10 10-23 6-37l-79-259c-7-22-13-37-20-43-7-7-19-10-37-10l-248 0c-5 0-9-2-11-5-2-3-2-7 0-12 4-13 18-20 41-20l264 0c5 0 10 2 16 5 5 3 8 6 10 11l85 282c2 5 2 10 2 17 7-3 13-7 17-13z m-304 0c-1-3-1-5 0-7 1-1 3-2 6-2l174 0c2 0 4 1 7 2 2 2 4 4 5 7l6 18c0 3 0 5-1 7-1 1-3 2-6 2l-173 0c-3 0-5-1-8-2-2-2-4-4-4-7z m-24-73c-1-3-1-5 0-7 2-2 3-2 6-2l174 0c2 0 5 0 7 2 3 2 4 4 5 7l6 18c1 2 0 5-1 6-1 2-3 3-5 3l-174 0c-3 0-5-1-7-3-3-1-4-4-5-6z"


        $modeBarButtonsToAdd[[1]]$click
        [1] "function(gd) { \n        // is this being viewed in RStudio?\n        if (location.search == '?viewer_pane=1') {\n          alert('To learn about plotly for collaboration, visit:\\n https://cpsievert.github.io/plotly_book/plot-ly-for-collaboration.html');\n        } else {\n          window.open('https://cpsievert.github.io/plotly_book/plot-ly-for-collaboration.html', '_blank');\n        }\n      }"
        attr(,"class")
        [1] "JS_EVAL"



        $cloud
        [1] FALSE

        Browse[3]> print(p$x)
        $visdat
        $visdat$`35446c1114b9`
        function () 
        plotlyVisDat
        <environment: 0x0000000019eb2c60>


        $cur_data
        [1] "35446c1114b9"

        $attrs
        $attrs$`35446c1114b9`
        $attrs$`35446c1114b9`$x
         [1]  1  2  3  4  5  6  7  8  9 10

        $attrs$`35446c1114b9`$y
         [1]  1  2  3  4  5  6  7  8  9 10

        $attrs$`35446c1114b9`$xaxis
        $attrs$`35446c1114b9`$xaxis$title
        [1] "tr"


        $attrs$`35446c1114b9`$yaxis
        $attrs$`35446c1114b9`$yaxis$title
        [1] "ts"


        $attrs$`35446c1114b9`$mode
        [1] "lines"

        $attrs$`35446c1114b9`$alpha_stroke
        [1] 1

        $attrs$`35446c1114b9`$sizes
        [1]  10 100

        $attrs$`35446c1114b9`$spans
        [1]  1 20

        $attrs$`35446c1114b9`$type
        [1] "scatter"



        $layout
        $layout$width
        NULL

        $layout$height
        NULL

        $layout$margin
        $layout$margin$b
        [1] 40

        $layout$margin$l
        [1] 60

        $layout$margin$t
        [1] 25

        $layout$margin$r
        [1] 10



        $source
        [1] "A"

        $config
        $config$modeBarButtonsToAdd
        $config$modeBarButtonsToAdd[[1]]
        $config$modeBarButtonsToAdd[[1]]$name
        [1] "Collaborate"

        $config$modeBarButtonsToAdd[[1]]$icon
        $config$modeBarButtonsToAdd[[1]]$icon$width
        [1] 1000

        $config$modeBarButtonsToAdd[[1]]$icon$ascent
        [1] 500

        $config$modeBarButtonsToAdd[[1]]$icon$descent
        [1] -50

        $config$modeBarButtonsToAdd[[1]]$icon$path
        [1] "M487 375c7-10 9-23 5-36l-79-259c-3-12-11-23-22-31-11-8-22-12-35-12l-263 0c-15 0-29 5-43 15-13 10-23 23-28 37-5 13-5 25-1 37 0 0 0 3 1 7 1 5 1 8 1 11 0 2 0 4-1 6 0 3-1 5-1 6 1 2 2 4 3 6 1 2 2 4 4 6 2 3 4 5 5 7 5 7 9 16 13 26 4 10 7 19 9 26 0 2 0 5 0 9-1 4-1 6 0 8 0 2 2 5 4 8 3 3 5 5 5 7 4 6 8 15 12 26 4 11 7 19 7 26 1 1 0 4 0 9-1 4-1 7 0 8 1 2 3 5 6 8 4 4 6 6 6 7 4 5 8 13 13 24 4 11 7 20 7 28 1 1 0 4 0 7-1 3-1 6-1 7 0 2 1 4 3 6 1 1 3 4 5 6 2 3 3 5 5 6 1 2 3 5 4 9 2 3 3 7 5 10 1 3 2 6 4 10 2 4 4 7 6 9 2 3 4 5 7 7 3 2 7 3 11 3 3 0 8 0 13-1l0-1c7 2 12 2 14 2l218 0c14 0 25-5 32-16 8-10 10-23 6-37l-79-259c-7-22-13-37-20-43-7-7-19-10-37-10l-248 0c-5 0-9-2-11-5-2-3-2-7 0-12 4-13 18-20 41-20l264 0c5 0 10 2 16 5 5 3 8 6 10 11l85 282c2 5 2 10 2 17 7-3 13-7 17-13z m-304 0c-1-3-1-5 0-7 1-1 3-2 6-2l174 0c2 0 4 1 7 2 2 2 4 4 5 7l6 18c0 3 0 5-1 7-1 1-3 2-6 2l-173 0c-3 0-5-1-8-2-2-2-4-4-4-7z m-24-73c-1-3-1-5 0-7 2-2 3-2 6-2l174 0c2 0 5 0 7 2 3 2 4 4 5 7l6 18c1 2 0 5-1 6-1 2-3 3-5 3l-174 0c-3 0-5-1-7-3-3-1-4-4-5-6z"


        $config$modeBarButtonsToAdd[[1]]$click
        [1] "function(gd) { \n        // is this being viewed in RStudio?\n        if (location.search == '?viewer_pane=1') {\n          alert('To learn about plotly for collaboration, visit:\\n https://cpsievert.github.io/plotly_book/plot-ly-for-collaboration.html');\n        } else {\n          window.open('https://cpsievert.github.io/plotly_book/plot-ly-for-collaboration.html', '_blank');\n        }\n      }"
        attr(,"class")
        [1] "JS_EVAL"



        $config$cloud
        [1] FALSE


        attr(,"TOJSON_FUNC")
        function (x, ...) 
        {
            jsonlite::toJSON(x, digits = 50, auto_unbox = TRUE, force = TRUE, 
                null = "null", na = "null", ...)
        }
        <environment: namespace:plotly>

When I reboot the computer, the problem still persists
I am now looking at deeper levels and it still seems all ok:
debugonce(as_widget)

debugonce(htmlwidgets::createWidget)

    Browse[4]> print(x)
    $visdat
    $visdat$e004cb169ef
    function () 
    plotlyVisDat
    <environment: 0x0000000005873be0>


    $cur_data
    [1] "e004cb169ef"

    $attrs
    $attrs$e004cb169ef
    $attrs$e004cb169ef$x
     [1]  1  2  3  4  5  6  7  8  9 10

    $attrs$e004cb169ef$y
     [1]  1  2  3  4  5  6  7  8  9 10

    $attrs$e004cb169ef$xaxis
    $attrs$e004cb169ef$xaxis$title
    [1] "tr"


    $attrs$e004cb169ef$yaxis
    $attrs$e004cb169ef$yaxis$title
    [1] "ts"


    $attrs$e004cb169ef$mode
    [1] "lines"

    $attrs$e004cb169ef$alpha_stroke
    [1] 1

    $attrs$e004cb169ef$sizes
    [1]  10 100

    $attrs$e004cb169ef$spans
    [1]  1 20

    $attrs$e004cb169ef$type
    [1] "scatter"



    $layout
    $layout$width
    NULL

    $layout$height
    NULL

    $layout$margin
    $layout$margin$b
    [1] 40

    $layout$margin$l
    [1] 60

    $layout$margin$t
    [1] 25

    $layout$margin$r
    [1] 10



    $source
    [1] "A"

    attr(,"TOJSON_FUNC")
    function (x, ...) 
    {
        jsonlite::toJSON(x, digits = 50, auto_unbox = TRUE, force = TRUE, 
            null = "null", na = "null", ...)
    }
    <environment: namespace:plotly>     


A: This is the correct form to achieve what you want, using plotly layouts:
TestPlotly=function()
{
   plot_ly(x = 1:10, y = 1:10,type="scatter",mode="lines") %>% 
    layout(
      xaxis = list(title="tr"),
      yaxis = list(title="ts")
      )

 }

Hope it helps!

A: I got the answer from Carson Sievert in person on the forum of plotly:
I've solved my problem by replacing layout() with plotly::layout()
I think that what got me was that I was using the layout from graphics instead of the layout from plotly because when I looked on google the only layout I found was the layout from graphics.
