Shiny code snippet not running in RStudio 1.2.5019

Hi,
I use the following code to center text in a well panel in several shiny apps:

   tags$head(tags$style(HTML("
                           #auc {
                            text-align: center;
                           #texto {
                            text-align: center;
                            }
                            }"))),

but the script file in RStudio 1.2.5019 doesn't run (hitting ctrl-enter), only when I rename the whole Script file to "app.R" and click on "run App". If I remove the above snippet, then it runs, but the text is no longer centered in the well panel. This does not happen with RStudio 1.2.1335.
I use Windows 10 home single language, version 1903. Please help.
Thanks.
Luis
REPREX:

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(
   tags$head(tags$style(HTML("
                           #auc {
                            text-align: center;
                                    }"))),  
   # Application title
   titlePanel("Old Faithful Geyser Data"),
   
   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30)
      ),
      
      # Show a plot of the generated distribution
      mainPanel(
         plotOutput("distPlot"),
         fluidRow(column(width = 8, offset = 2,
                         
                         h4(htmlOutput(outputId = "auc"))
                         
                         
         ))
      )
   )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
   
   output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2] 
      bins <- seq(min(x), max(x), length.out = input$bins + 1)
      
      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
   output$auc <- renderUI({
      
      wellPanel(
         HTML( "<h4>" ,"Text to be centered","</h4>",
               '<p><span style="color: #ff0000;">',
               "Result to be centered",'</span></p>')
      )
   })
}

# Run the application 
shinyApp(ui = ui, server = server)

Hi, and thanks for the reprex.

I cut and pasted your code into my demo.Rmd file and shift enter produced exactly what I'd expect. I tried it in an untitled empty file with nothing but your code and that also worked, with or without first selecting the code.

So, we must be doing something different, other than the operating system.

What happens when you create a new RMarkdown file, select all and delete to create a blank file, paste in your reprex and then hit control enter? Same trouble? If not, what are you doing differently when the problem occurs?

Hi, thanks for your response.
You are right, I don't have the problem when I open a RMarkdown file. The problem arises when I run the code in a Script file reprex.R. Did you tried to run the code in a Script file? I tried in another computer, ugrading RStudio to the new version and I was able to reproduce the problem (in a Script file). I have to point out that if I select the whole code of the fluidPage function and hit ctrl-enter, then it runs the code. Normally, if I place the cursor on the first line of the function and hit ctrl-enter, R runs the code all the way down to the next function (server). With the problem, it halts in the function sidebarPanel, and pressing ctr-enter only makes the previous code to rerun in the console. To stop the process, I have to click twice on the Runapp utility of the script file window, and after an error message: Error: unexpected symbol in:
"runApp('reprex.R')
runApp
I am able to continue my work.
Hope this helps.
Luis

I get the identical behavior in reprex.R, reprex.Rmd (with the rmarkdown header), reprex.txt and an unnamed, unsaved screen, makes no nevermind.

Try CTRL-SHIFT-ENTER or for MAC OS CMD-SHIFT-ENTER, which will source the entire file wherever the cursor happens to be.

Thank you. It is wierd that you can't reproduce the problem. May be the system language? Mine is in Spanish.
Any way, I will manage to select the whole chunk of code before running it.
Thanks for your time.
Luis

1 Like

¿Quién sabe? La vida es un sueño. :grin:

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.