Show the euro simbol in a shiny R application -
i'm trying create shiny r application. have troubles show euro symbol (and return it) in radio button. i've tried different version of code:
library(shiny) runapp(list( ui= navbarpage(title = 'shoe euro', radiobuttons('var', 'var', c("income_mgl", "income_mgl€", "income_mgl€", "income_mgl€", "income_mgl\u20ac") )), server=function(input, output, session) { }))
but "€" doesn't appear in web page. if select second option page returns error:
"error in fromjson(content, handler, default.size, depth, allowcomments, : invalid json input"
the problem lies in class shiny-options-group
in div
function. way class works appears convert &
&
, preventing browser converting €
€
because first changes €
. try following ui.r see happen.
library(shiny) options = as.list(c("a","b",html("€"),"€")) shinyui(fluidpage("test",fluidrow(div(class = "shiny-options-group", options))))
the reason happening in radio button widget radiobuttons
calls generateoptions
create list of options, , generateoptions
returns div(class = "shiny-options-group", options)
, options
derived manipulation of choices
parameter in radiobuttons
function. here do:
- get code
generateoptions
here (line 653). - define new function
generateoptions2
using exact same codegenerateoptions
, change class parameter @ end. - get code
radiobuttons
runningshiny::radiobuttons
- define new function
radiobuttons2
, in replacegenerateoptions
generateoptions2
. - set environment both new functions
shiny
runningenvironment(radiobuttons2) <- environment(radiobuttons)
- use
radiobuttons2
in code instead ofradiobuttons
the thing don't know change class parameter in generateoptions2
. don't know div
classes.
update
i may have spoken soon. looks problem goes far deeper. div
function calls tags$div
, calls tag
first argument set "div"
. tag
calls base function structure
parameter class = "shiny.tag"
. structure
calls primitive function attributes
parameter class = "shiny.tag"
. attributes
parameter converts &
in &
. therefore, looks there no way use div
function , euro symbol. tried replacing div
in generateoptions2
html
, returned bunch of garbage when ran app. you'd have change behavior of class = "shiny.tag"
, have far-reaching unpredictable effects.
update 2
figured out! trick use gsub
replace every &
&
before returned generateoptions2
. put functioning version of posted on github. requires loading 2 functions mentioned earlier, (in repository) stored in file called functions.r
. important line in generateoptions2
gsub(pattern = "&", replacement = "&", div(class = "shiny-options-group", options))
.
Comments
Post a Comment