This MWE is working:
library(shiny)
library(shinydashboard)
library(shinyMCE)
ui<-dashboardPage(header=dashboardHeader(),
sidebar=dashboardSidebar(),
body=dashboardBody(#uiOutput("body")
tinyMCE("tinyInput","Some html text")
))
server <- function(input, output, session) {
#output$body <- renderUI({tinyMCE('tinyInput',"Some html text")})
}
shinyApp(ui = ui, server = server)
This is how it looks like:
However, if I use the tinyMCE inside renderUI:
library(shiny)
library(shinydashboard)
library(shinyMCE)
ui<-dashboardPage(header=dashboardHeader(),
sidebar=dashboardSidebar(),
body=dashboardBody(uiOutput("body")
#tinyMCE("tinyInput","Some html text")
))
server <- function(input, output, session) {
output$body <- renderUI({tinyMCE('tinyInput',"Some html text")})
}
shinyApp(ui = ui, server = server)
..it does not work properly:
I need to use renderUI because I have several elements to render in the body.
Any suggestion?
As I saw in here.
I added the source of the script in a singleton:
library(shiny)
library(shinydashboard)
library(shinyMCE)
ui<-dashboardPage(header=dashboardHeader(),
sidebar=dashboardSidebar(),
body=dashboardBody(singleton(tags$head(tags$script(src = "//cdn.tiny.cloud/1/5a5deew2z9gml5pwn95iosioop446qny3vyfh994kujzkwu6/tinymce/5/tinymce.min.js", referrerpolicy="origin"))),
uiOutput("body")
#tinyMCE("tinyInput","Some html text")
))
server <- function(input, output, session) {
output$body <- renderUI({tinyMCE('tinyInput',"Some html text")})
}
shinyApp(ui = ui, server = server)
It fixed my problem.
Related
I am having a shiny app with some ui elements.
Is there a way to replace some HTML (e.g. div / div content) with an animation effect, similar to what shinyjs::show(anim=T) does?
library(shiny)
library(shinyjs)
ui <- fluidPage(
shinyjs::useShinyjs(),
actionButton("change","change"),
tags$div(id="someDiv",
"test"),
hidden(tags$div(id="withAnim", "Displayed with animation"))
)
server <- function(input, output) {
observeEvent(input$change, {
shinyjs::html("someDiv", "changed without animation")
shinyjs::delay(1000, show("withAnim", anim=T, animType="fade"))
})
}
shinyApp(ui = ui, server = server)
the shinyjs::html doesn't provide this utility. We can write our own js code and use shinyjs::runjs to run it when button is clicked.
library(shiny)
library(shinyjs)
ui <- fluidPage(
shinyjs::useShinyjs(),
actionButton("change","change"),
tags$div(id="someDiv",
"test"),
hidden(tags$div(id="withAnim", "Displayed with animation"))
)
server <- function(input, output) {
observeEvent(input$change, {
shinyjs::runjs("$('#someDiv').fadeOut(500, function(){$(this).text('changed without animation').fadeIn();})")
shinyjs::delay(1000, show("withAnim", anim=T, animType="fade"))
})
}
shinyApp(ui = ui, server = server)
I want the text in an HTML tag to be different sizes and red.
In this code, the different sizes works, but the red does not.
library(shiny)
ui <- fluidPage(
HTML("<p style=font-size:28px; font-color:red;>Hello</p><p style=font-size:22px>There</p>"),
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
You have to use color:red instead of font-color:red and it has to be before the font-size tag.
This is the corrected code:
library(shiny)
ui <- fluidPage(
HTML("<p style=color:red;font-size:28px; >Hello</p><p style=font-size:22px>There</p>"),
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
Is there a way to use a web image as cursor when hovering over a button?
I tried something like this:
tags$head(tags$style(HTML(" .custom { cursor: url(https://c2.staticflickr.com/2/1907/31794847918_04f9e687e1_b.jpg), auto;
} ")))
which has no effect, and I can't find any other examples on the web how to manage this in R shiny.
library(shiny)
ui <- fluidPage(
actionButton(inputId = 'messagebutton', label = 'click me')
)
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)
This example works for me. I think your image isnt working, but I'm not sure why exactly. It might be too big.
library(shiny)
csscode <- HTML("
#messagebutton {
cursor: url(http://www.javascriptkit.com/ajax.gif), auto;
}
")
ui <- fluidPage(
tags$head(tags$style(csscode)),
actionButton(inputId = 'messagebutton', label = 'click me')
)
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)
By default tabs in a tabsetPanel are put on the left. Is it possible to place a tab on the right side, while still having other tabs on the left? So that it looks like this?
library(shiny)
ui <- fluidPage(
tabsetPanel(
tabPanel("tab_left1"),
tabPanel("tab_left2"),
tabPanel("tab_right")
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
Using float-right should indeed work. The problem with using 2 tabsetPanel is that there are 2 active tabs at the same time.
library(shiny)
ui <- fluidPage(
tags$head(
tags$style(HTML(
".tabbable ul li:nth-child(3) { float: right; }"
))
),
tabsetPanel(
tabPanel("tab_left1"),
tabPanel("tab_left2"),
tabPanel("tab_right")
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
Maybe you can create 2 tabsetPanel and pull one over to the right?
rm(list = ls())
library(shiny)
ui <- fluidPage(
div(style="display:inline-block",tabsetPanel(type = c("pills"),tabPanel("tab_left1"),tabPanel("tab_left2"))),
div(style="display:inline-block;float: right",tabsetPanel(type = c("pills"),tabPanel("tab_right")))
)
server <- function(input, output, session) {}
shinyApp(ui, server)
When you apply the class float-right to the ones you want to float to the right, it should do the trick.
How can I print the current page in R shiny web applications? It is possible in HTML by using the command of window.print();. But I could not find and implement its correspondent R Shiny command. What is on my mind is something like the following? How can I call an html command in SERVER?
actionButton("print", "PRINT")
server <- function(input, output) {
observeEvent(input$print, {
window.print();
})
}
This can be done using shinyjs package to call a js function.
library(shiny)
library(shinyjs)
jsCode <- 'shinyjs.winprint = function(){
window.print();
}'
ui <- shinyUI(fluidPage(
useShinyjs(),
extendShinyjs(text = jsCode, functions = c("winprint")),
actionButton("print", "PRINT")
))
server <- shinyServer(function(input, output) {
observeEvent(input$print, {
js$winprint()
})
})
shinyApp(ui, server)