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)
Related
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.
I have two modals. When the first is opened, the background should be grayed out, as is default. But this should not happen with the second one. The code is:
library(shiny)
ui <- fluidPage(
tags$style(type = 'text/css', '.modal-backdrop { display: none }'),
actionButton('modal1', 'Modal1'),
actionButton('modal2', 'Modal2'),
)
server <- function(input, output) {
observeEvent(input$modal1,
showModal(modalDialog(title = "Modal1"))
)
observeEvent(input$modal2,
showModal(modalDialog(title = "Modal2"))
)
}
shinyApp(ui = ui, server = server)
The css code should be connected to the id of the second modal dialog, but it is not possible to include an id in the function 'modalDialog'.
Any ideas about how to apply the css code selectively to only the second modal?
You can add JS code to hide the backdrop after showing the second modal using tags$script just after modalDialog.
library(shiny)
ui <- fluidPage(
actionButton('modal1', 'Modal1'),
actionButton('modal2', 'Modal2'),
)
server <- function(input, output) {
observeEvent(input$modal1,
showModal(modalDialog(title = "Modal1"))
)
observeEvent(input$modal2, {
showModal(
list(
modalDialog(title = "Modal2"),
tags$script("$('.modal-backdrop').css('display', 'none');")
)
)
})
}
shinyApp(ui = ui, server = server)
Hello.
I am trying to align the materialSwitch checkbox with some pickerInput boxes.
Here's what it looks like vs what I want it to look like:
Here is a simplified code of the problem, help please!
library(shiny)
library(shinydashboard)
library(shinyWidgets)
#----------------------------------------------------------------------------#
ui <- {dashboardPage(
dashboardHeader(title=""),
dashboardSidebar(),
dashboardBody(
fluidRow(box(column(materialSwitch("t0"),width=1),
column(pickerInput(inputId="t1",label="",choices=c("Yes","No")),
pickerInput(inputId="t2",label="",choices=c("Yes","No")),width=3),
column(pickerInput(inputId="t3",label="",choices=c("Yes","No")),
pickerInput(inputId="t4",label="",choices=c("Yes","No")),width=4),
column(pickerInput(inputId="t5",label="",choices=c("Yes","No")),
pickerInput(inputId="t6",label="",choices=c("Yes","No")),width=4),
actionButton("t7","",width="100%"),width=12))))
}
#----------------------------------------------------------------------------#
server <- function(input, output) {}
#----------------------------------------------------------------------------#
shinyApp(ui = ui, server = server)
Also, if there's a way to tighten the space, or reduce the margin between the switch and the input boxes that would swell. My current code also makes one of the pickerInputs at a different width than the others (to include the switch), if there's a way to proportion them so they're all the same width that would be extra swell.
Thanks.
You can apply some css to move the materialSwitch.
div(column(materialSwitch("t0"),width=1), style = 'top: 25px;position:relative;')
Complete code -
library(shiny)
library(shinydashboard)
library(shinyWidgets)
#----------------------------------------------------------------------------#
ui <- {dashboardPage(
dashboardHeader(title=""),
dashboardSidebar(),
dashboardBody(
fluidRow(box(div(column(materialSwitch("t0"),width=1), style = ' top: 25px;position: relative;'),
column(pickerInput(inputId="t1",label="",choices=c("Yes","No")),
pickerInput(inputId="t2",label="",choices=c("Yes","No")),width=3),
column(pickerInput(inputId="t3",label="",choices=c("Yes","No")),
pickerInput(inputId="t4",label="",choices=c("Yes","No")),width=4),
column(pickerInput(inputId="t5",label="",choices=c("Yes","No")),
pickerInput(inputId="t6",label="",choices=c("Yes","No")),width=4),
actionButton("t7","",width="100%"),width=12))))
}
#----------------------------------------------------------------------------#
server <- function(input, output) {}
#----------------------------------------------------------------------------#
shinyApp(ui = ui, server = server)
Accidentally i saw this User Interface in a website, the first thing that i tought was "oh... this is a shiny ui, seems like the developer use shinydashboard::dashboardHeader(), shinydashboard::dashboardBody() and shinydashboard::dashboardSidebar()", Well but how to do this? I never saw a function to create something similar.. i realize the actionButton() but how to do this:
library(shiny)
ui <- fluidPage(
# here
actionButton("button","Faça Login e assine")
)
server <- function(input, output, session) {
observeEvent(input$button, {
## do something
})
}
shinyApp(ui, server)
You can use the normal box() function of shiny along with hr() and do something like this:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title="TITLE",status="primary",solidHeader=TRUE,style="",
width=2,
h1(strong("$89,90")),
h5("Some text here"),
hr(),
h4("More text"),
hr(),
h4("More text"),
hr(),
h4("More text"),
hr(),
h4("More text"),
hr(),
actionButton("button","Login and subscribe",class="btn-primary")
))
)
server <- function(input, output, session) {
observeEvent(input$button, {
## do something
})
}
shinyApp(ui, server)
This gives an output like :
After this, you can always use css to customize the colors and the fonts in your box.
I hope this answers your question!
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)