Shiny app radioButtons invisible in RStudio viewer pane - r

The RStudio (Version 1.2.1139 on macOS) viewer pane renders radioButtons (and FWIW, selected checkboxInputs) invisible. But these look and work fine in the browser, when 'Run External' is selected under the 'Run App' button. Below is a repro, and some screenshots.
Addendum: I note that shinyWidgets::prettyRadioButtons() resolves this issue immediately. Simply add library(shinyWidgets) at the top, and replace the call to radioButtons().
# Reproduce radioButtons invisibility in RStudio viewer pane
library(shiny)
ui <- fluidPage(
radioButtons("Dunit"
,"Dose Units"
,c("µg"="micrograms",
"mg"="milligrams",
"g"="grams")
,selected = "milligrams"
,inline = TRUE)
,checkboxGroupInput("Dper"
,NULL
,c("/m²"="perBSA",
"/kg"="perKg",
"abs"="absolute")
,selected = "perKg"
,inline = TRUE)
)
server <- function(input, output) {}
# Run the application
shinyApp(ui = ui, server = server)
In RStudio viewer pane:
In External browser:

This is a known issue in Chromium (the component powering RStudio's viewer) on MacOS. You can work around it by adding zoom: 1.0000001 or similar to the CSS that styles radio buttons for your Shiny app.
More info in this RStudio Github issue:
https://github.com/rstudio/rstudio/issues/3751

Related

Run App gives no result R shiny app and crashes RStudio

I'm having an issue with the running of a R shiny app. Here's what I do:
open RStudio
load the shiny code (e.g. app.R)
set the wd
library(shiny)
press on "Run App"
Then nothing happens.
And if I try to terminate the execution, R does not answer anymore and says to force the closing of RStudio.
Here's one of my codes (I tried some, so I don't think this is the issue, but I report one anyway):
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
titlePanel("Un'applicazione con uno slider"),
sidebarLayout(
h1("Sposta lo Slider!"),
sliderInput("slider1", "Spostami!", 0, 100, 0)
),
mainPanel(
h3("Valore dello slider:"),
textOutput("text")
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$text <- renderText(input$slider1)
}
# Run the application
shinyApp(ui = ui, server = server)
Do you have any advice to give me in order to make anything happen? I have no errors shown, so I don't know what to do...
I just see "runApp(...mypath.../app)" and blank space after it.
Thank you in advance.
Edit 1:
I also tried this, but nothing happened (as before):
library(shiny)
runExample("01_hello")
Edit 2: Copy-pasting the code directly in the console doen not work either
I was experiencing the same issue with R 4.1 on Windows 10. Updating all packages seems to have solved it:
update.packages(ask = FALSE, checkBuilt = TRUE)

Is it possible to display an info text when hovering over a R shiny selectInput?

I am currently building a shiny app to build biological networks. To build them, you can choose between many different parameters, which i included in different selectInputs or numericInputs.
Is it possible to have some kind of info text, when hovering the mouse over those input fields? I dont want to add 3-4 sentences of text to the title of each select/numericInput.
Thanks :)
If you don't mind an extra package dependancy then you can use bsTooltip from the shinyBS package. Note that the hover tooltip sometimes doesn't show up unless you click on the input in the RStudio viewer pane, but if you run your app in your browser, the hover trigger should work:
library(shiny)
library(shinyBS)
ui <- fluidPage(
selectInput("input1", "Select input", c("choice1", "choice2")),
bsTooltip(id = "input1",
title = "Here is some text with your instructions")
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)

Changing title of shinyjs alert in R

I am building a R shiny app and am using the shinyjs::alert function to let users know when a submission is successful. The default header for the pop-up is a 127 IP address. Can this be changed to a string of different text? Ideally the name of my organization would be used in its place.
The code below is swiped from the shinyjs::alert documentation with minor edits to create a button that sends the message "Hello World!" as an popup.
if (interactive()) {
library(shiny)
library(shinyjs)
shinyApp(
ui = fluidPage(
useShinyjs(), # Set up shinyjs
actionButton("btn", "Click me")
),
server = function(input, output) {
observeEvent(input$btn, {
# Change the following line for more examples
alert("Hello world!")
})
}
)
}
Edit:
When run on a windows OS on microsoft edge the default message appears as
You could use an external package for this:
shinyalert: https://daattali.com/shiny/shinyalert-demo/
shinyWidgets: https://github.com/dreamRs/shinyWidgets#sweet-alert
When I run your code in Linux (on Firefox) this is how it looks:
Maybe the window title is coming from your browser / operating system?

How to play local video in shiny app?(Windows)

I tried the follow code:
shinyUI(
fluidPage(
tags$video(id="video2", type = "video/mp4",src = "sample.mp4", controls = "controls")
)
)
shinyServer(function(input, output, session){})
But, it returns a blank page,
How should I do to play the video?
For anyone late to this question - it won't play in RStudio's 'Run App' environment - launch your app to the browser and it seems to work fine.

R shiny dynamically render audio [close]

I am working on a project, trying to render audio dynamically. That is, I can click a button and play a selected local audio.
I have read this post and tried zedii's trick. The problem remains still.
Well I build a test app as shown below.
library(shiny)
# test set ----
ui <- fluidPage(
textInput('my_music','path:',value="questionF"),
actionButton("ok", "Okay"),
uiOutput('my_audio')
# tags$audio(src = "questionF.mp3", type = "audio/mp3")
)
get_audio_tag <- function(filename) {
tags$audio(src = filename,
type = "audio/mp3",
controls = "controls")
}
server <- function(input, output, session){
# Render the audio player
observeEvent(input$ok, {
wav_name = input$my_music
# output$my_audio <-renderUI(get_audio_tag("questionF.mp3"))
output$my_audio <-renderUI(get_audio_tag(wav_name))
})
}
shinyApp(ui = ui, server = server)
When I click the button, the first song turns out okay. But the following ones seemed pretty hard to load, for my computer would freeze with the memory used by Rstudio rising.
Any thoughts will be appreciated.
updates:
I tried on different browsers. These codes would failed on Chrome but works fine on Microsoft edges.
Looks like a caching problem.
So now my question is how can I make the codes work on every platform using shiny/R?
My codes works on most browser other than Chrome. I think it's more like a Chrome's problem.

Resources