Render Elements are not shown in a shiny tab - r

I want to add a tabset in my shiny semantic page. Elements that are defined directly in the tab are shown in the app, but render objects do not appear. Here an example:
UI.R:
library(shiny)
shinyUI(semanticPage(
suppressDependencies("bootstrap"),
shinyjs::useShinyjs(),
tabset(tabs=
list(
list(menu="First Tab", content=
div(class="ui text shape",
div(class="sides",
div(class="ui header side active","This side starts visible."),
div(class="ui header side","This is yet another side"),
div(class="ui header side","This is the last side")
),
tags$button(id="test",class="ui button","Flip")
)),
list(menu="Second Tab",content=plotOutput("plot1"))
))
))
Server.R:
library(shiny)
library(shinyjs)
library(shiny.semantic)
library(highlighter)
jsCode <- "
$(document).ready(function() {
$('.shape').shape();
$('#test').on('click', function(){$('.shape').shape('flip up');});
});
"
shinyServer(function(input, output) {
runjs(jsCode)
output$plot1 <- renderPlot(plot(1,1))
})
Here the renderplot "plot1" is not shown in the tab. How can I fix this issue?

Related

change color of datatable filter dropdown box

Hello.
I would like to change the color of this dropdown box which appears for numeric filters.
Sample code:
library(DT)
library(shiny)
ui <- basicPage(
h2("The mtcars data"),
DT::dataTableOutput("mytable")
)
server <- function(input, output) {
output$mytable = DT::renderDataTable({
DT::datatable(mtcars,filter="top")
})
}
shinyApp(ui, server)
Thanks
You only have to modify the suitable CSS on the ui function:
ui <- basicPage(
h2("The mtcars data"),
DT::dataTableOutput("mytable"),
tags$style(type = "text/css",
".noUi-connect {background: red;}")
)
Update
As explained in the comments, you can see in the next image (open it to see larger) where is the CSS modified to get a dark red where you want (in the right column of left window above is the element.style to which my comment below refers). The issue I am not able to solve is how to modify that tag (the shadowed one at the left) ` without a class or an id, with CSS or Shiny.

Using the "click" function to programatically launch R shiny Action Button

I recently came across the click() function and want to incorporate this in to my app.
https://www.rdocumentation.org/packages/shinyjs/versions/1.1/topics/click
However attempting to run the given example:
if (interactive()) {
library(shiny)
library(shinyjs)
shinyApp(
ui = fluidPage(
useShinyjs(), # Set up shinyjs
"Count:", textOutput("number", inline = TRUE), br(),
actionButton("btn", "Click me"), br(),
"The button will be pressed automatically every 3 seconds"
),
server = function(input, output) {
output$number <- renderText({
input$btn
})
observe({
click("btn")
invalidateLater(3000)
})
}
)
}
# }
Did not give the desired behaviour. It appears no auto-clicking is taking place! Can anybody explain? Thanks in advance.

How can I change the text size in Shiny modals?

I successfully changed the text sizes in shiny dashboard interface by editing css file.
Or I use following structure:
div(DTOutput(outputId = "table"), style = "font-size:85%"))
However, I couldn't find the node name of shiny modals. Is it possible to change the text size in shiny modals through .css?
Are you looking for something like this?
shinyApp(
ui = basicPage(
actionButton("show", "Show modal dialog")
),
server = function(input, output) {
observeEvent(input$show, {
showModal(modalDialog(
title = "Important message",
div("This is an important message!", style="font-size:160%")
))
})
}
)
ModalDialog takes as its first argument(s) UI elements. This appears to be the same kind of arguments accepted by other shiny elements. Compare for example: ?siderbarPanel and ?modalDialog. So if you can do it in the body of an app, you can probably do it in a modal.
For example, I stuck a sidebar layout inside a modal:
shinyApp(
ui = basicPage(
actionButton("show", "Show modal dialog")
),
server = function(input, output) {
observeEvent(input$show, {
showModal(modalDialog(
sidebarLayout(sidebarPanel("yeah"),mainPanel("cool"))
))
})
}
)

Clear the main Panel to display the other reactive output in shiny r studio

I have a dataTableOutput in my main panel. Then I have an action button "Go". Once I click "Go" I want rHandsOutput to appear in the main panel but not beneath dataTableOutput. How can I remove dataTableOutput in the main panel and display rHandsOutput. In my current code both tables appearing together. Once I click "Go", the second table comes under the first table where I want to appear only second table (rHandsOutput) removing 1st table from the main panel.
Please help me!1
You can use a combination of insertUI and removeUI to make UI components dynamic. For example:
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
actionButton(inputId = "go", label = "Go")
),
mainPanel(
fluidRow(
tags$div(id = "firstOutput",
dataTableOutput("myDataTable"))
),
fluidRow(
tags$div(id = "placeholder") # the dynamic UI will be inserted relative to this placeholder
)
))
)
server <- function(input, output) {
output$myDataTable <- renderDataTable(iris)
observeEvent(input$go, {
removeUI("div:has(>#firstOutput)")
insertUI(
selector = "#placeholder",
where = "afterEnd", # inserts UI after the end of the placeholder element
ui = fluidRow(
actionButton(inputId = "newButton", label = "A new button")))
})
}
shinyApp(ui = ui, server = server)
You can use showElement() and hideElement() from shinyjs:
observeEvent(input$go, {
shinyjs::hideElement(“firsttable”)
shinyjs::showElement(“rHandsOutput”)
})
Assuming the ID of the first table is “firsttable” and the ID of the second table is “rHandsOutput”, and the ID of the “Go” button is “go”.
Generate the ui dynamically.
Use uiOutput("someidentifier") in the ui.r and then fill it with your datatable with the following in server.r
output$someidentifier <-
renderUI({
dataTableOutput("datatableidentifier")
})
output$datatableidentifier <- renderDataTable(iris)
uiOutput takes the place (in ui.r) of whatever ui element you want to add dynamically. The necessary code for that ui then moves to renderUI in server.r.

Shiny: adding addPopover to actionLink

I want to include a small "Help" actionLink (next to a "Render" actionButton) that acts as a popover (see here). Here's my code:
server.R:
shinyUI(pageWithSidebar(
sidebarPanel(
actionButton("renderButton", "Render"),
actionLink("link", "Help") ),
mainPanel()
))
ui.R:
shinyServer(function(input, output, session) {
# ... dealing with renderButton ...
output$link <- renderUI({
addPopover(session=session, id=output$link, title="",
content="Testing.", placement = "bottom",
trigger = "click", options = NULL)
})
})
Right now, the actionLink shows up on the sidebar, but clicking on it has no effect. Any tips? I think it may have to do with the id in addPopover, but I haven't found many examples to provide a framework. I found this, but I want to deal with the popover in server.R, not ui.R. Can it be done this way, or should I just make the popover in ui.R?
From ?Tooltips_and_Popovers:
There must be at least one shinyBS component in the UI of your app in
order for the necessary dependencies to be loaded. Because of this,
addTooltip and addPopover will not work if they are the only shinyBS
components in your app.
To get the pop over to work, you can change your actionButton into a bsButton, and modify server.R to only contain the call to addPopover. The id argument to addPopover also needs to be changed to refer to the id of the ui object you want the pop over to appear on, in your case "link", the id of the actionLink .
Here's the modified example code in a self-contained code chunk:
library(shiny)
library(shinyBS)
runApp(
# Ui
list(ui = pageWithSidebar(
headerPanel("Test App"),
sidebarPanel(
bsButton("renderButton", "Render"),
actionLink("link", "Help") ),
mainPanel("Hello World!")
),
# Server
server = function(input, output, session) {
# ... dealing with renderButton ...
addPopover(session=session, id="link", title="",
content="Testing.", placement = "bottom",
trigger = "click", options = NULL)
})
)

Resources