Broad lines
The general lines or principles that will guide the construction of the question are the same listed here, here and in the link quoted in the question. What will change in the Shiny is as implement these principles.
These principles can be summarised as follows::
- Share the data used (or at least a part of them);
- Share a minimum code which reproduces the problem
- Share the result obtained (generated error messages, warnings or screens);
- Share what would be the expected result with the shared code;
- Share the session information (version of r, used packages) with
sessionInfo()
.
How items 1 and 5 are solved in the same way as for the r in general, the rest of the response focuses on items 2 to 4.
Say the question was:
How to allow the user to choose a data set in a Shiny?
Minimum code
Step 1: Reproduce the problem
In order for others to help, they will need to reproduce their problem. So start a new file (app.R
) and insert in it the code of your Shiny.
At this stage if there is a global.R
in that Shiny, this will be the first content of the new script. Then copy and paste the contents of ui.R
and server.R
defining the variables ui
and server
. End up calling the function shinyApp(ui, server)
with the newly created objects.
The great advantage of presenting your application in a single script is that it facilitates the life of those who will answer the question, as just a Ctrl + c and Ctrl + v to get the application running and start working on solving the problems presented.
Thus we would end up with a content similar to what follows in app.R
.
# antigo global.R
library(shiny)
library(lubridate)
gerar_valores <- function(x) {
rnorm(x, 10, 2)
}
set.seed(123)
# antigo ui.R
ui <- fluidPage(
column(
6,
sliderInput("n", "Quantidade de observações", 30, 100, 65),
plotOutput("hist")
),
column(
6,
selectInput("dados", "Selecione o conjunto de dados",
choices = list(carro = mtcars, flores = iris)),
plotOutput("plot")
)
)
# antigo server.R
server <- function(input, output, session) {
output$hist <- renderPlot({
hist(gerar_valores(input$n))
})
output$plot <- renderPlot({
plot(input$dados)
})
}
shinyApp(ui, server)
Step 2: Isolate the problem
In the application of the above script we have two inputs and two outputs, but the problem is related only to a set of input/output.
Providing all the application code in question, before helping will mess up. This is because whoever is going to address the problem will have an extra job (identify which part of the script comes from the error). In some cases, this can even cause you to give up helping.
To isolate the problem is enough get rid of all the code that has no relation to it. In the above example this means removing all of the code related to the creation of histograms both in the ui
how much in the server
. Then we would have:
# antigo global.R
library(shiny)
# antigo ui.R
ui <- fluidPage(
selectInput("dados", "Selecione o conjunto de dados",
choices = list(carro = mtcars, flores = iris)),
plotOutput("plot")
)
# antigo server.R
server <- function(input, output, session) {
output$plot <- renderPlot({
plot(input$dados)
})
}
shinyApp(ui, server)
Result obtained
To share the result obtained with the shared code there are at least 3 options.
Describe unwanted behavior found;
Share a link to the application with the problem. Among the services that may host your Shiny can I quote the shinyapps.io and the now.sh.
Share a screenshot of the application with the problem.
Regardless of the method you choose, don’t forget to share error messages or warnings from both the console and the ui
of the application.
In the above case we would have something like:
The list of options, instead of displaying the names of the data sets, presents a series of names and numbers, as shown below. I also get these errors on my console:
Warning in min(x) :
no missing argument for min; returning Inf
Warning in max(x) :
no missing argument for max; returning -Inf
Warning: Error in Plot.window: finite values are required for 'ylim'
[No stack trace available]
Expected result
To explain the result I expected I see 3 options:
Describe in words the expected result;
Share a link to a case (another application or page) that is serving as inspiration;
Rotate the desired result outside the Shiny and share it.
In the fictional example, it could be something like.
I get the result I’m waiting for with the command
plot(mtcars)
Why doesn’t it work inside the Shiny?
Other materials (HTML/CSS/JS)
The same principles used for the code r can be used for other languages: share only the essential and if you are problem-related shared. Share each into a piece of code within the question. Something like:
This is the css that I’m wearing:
.resultado {
background-color: green;
}
That question shouldn’t be on the finish line?
– Costamilam
No. It is about a technical difficulty how to make an application in
shiny
reproducible. This can be used for Sopt, but also to submit issues to package maintainers, etc.– Tomás Barcellos