Cannot render flow chart in R shiny - r

I want to display a flow chart in shiny, it just not showing in shiny browsers, but displays in the viewer pane in rstudio.
library(shiny)
library(DiagrammeR)
ui <- fluidPage(
plotOutput(outputId ="temp")
)
server <- function(input, output, session) {
plotInput = function(){
DiagrammeR(paste('graph LR',
sprintf("A(%s)-->B", iris[1,1]),
sep = ';'))
}
output$temp<-renderPlot(
plotInput()
)
}
shinyApp(ui, server)

Related

renderPlot outputs plot in View, not browser

My goal is to plot the output, a process map, onto the browser. The output plot continues to appear in the Viewer pane in RStudio.
All of the functionality works as expected and I'm able to call the appropriate data and generate a dynamic output based on the dropdown menu.
Any help would be much appreciated. Full code is below.
library(shiny)
library(bupaR)
library(pm4py)
library(reticulate)
library(processmapR)
ui <- fluidPage(
tags$h1("Process Mining"),
tags$p("The purpose of this application is to show the Process Map output"),
fluidRow(
selectInput("pm_type","Process Mining Type", c("absolute","relative"))),
fluidRow(
plotOutput("plot1"))
)
server <- function(input, output) {
selectedData <- reactive({input$pm_type})
output$plot1 <- renderPlot({
patients %>%
process_map(type = frequency(selectedData()))
})
}
shinyApp(ui = ui, server = server)
To get output of process_map in shiny you have to use GrViz functions from DiagrammeR.
library(shiny)
library(bupaR)
library(pm4py)
library(reticulate)
library(processmapR)
library(DiagrammeR)
ui <- fluidPage(
tags$h1("Process Mining"),
tags$p("The purpose of this application is to show the Process Map output"),
fluidRow(
selectInput("pm_type","Process Mining Type", c("absolute","relative"))),
fluidRow(
grVizOutput("plot1"))
)
server <- function(input, output) {
selectedData <- reactive({input$pm_type})
output$plot1 <- renderGrViz({
patients %>%
process_map(type = frequency(selectedData()))
})
}
shinyApp(ui = ui, server = server)

Shiny: Render Outputs when hidden

I am trying to render a few outputs in a shiny application that are contained within a shinyjs::hidden section upon the application running rather than once the section is visible.
EDIT: I had the app set up incorrectly in the original example so have changed it.
I want to be able to run the reactive statement before running the final observe to change the UI from the Alpha text to the Beta text and plot. Ideally this would mean in the console would see "Done plotting" before "Observe run".
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
div(id = "before-content", h3("Aux Text Alpha")),
shinyjs::hidden(
div(
id = "after-content",
h1("Aux Text Beta"),
plotOutput("text")
)
)
)
server <- function( session,input, output) {
in_plot <- reactive({
Sys.sleep(3)
print("Done plotting")
plot(iris)
})
output$text <- renderPlot({
in_plot()
})
observe({
print("Observe run")
hide("before-content")
show("after-content")
})
}
shinyApp(ui, server)
An alternative would be to have a layer over what is classed as the hidden section but am not too sure on how that is accomplished.
You can hide it in the reactive, like so:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
actionButton("button", "Click me"),
plotOutput("text")
)
server <- function( session,input, output) {
in_plot <- reactive({
hide("text")
Sys.sleep(3)
print("Done plotting")
plot(iris)
})
output$text <- renderPlot({
in_plot()
})
observeEvent(input$button, {
show("text")
})
}
shinyApp(ui, server)

Adjust the position of actionButton widget in R shiny DT table

The given R shiny script creates a simple data table as in the snapshot with an actionButton in the center. I want to place the button a little below it's current position such that it is in perfect horizontal inline position to the search bar. Thanks and please help.
library(DT)
library(shiny)
library(shinyBS)
library(rpivotTable)
library(bupaR)
ui <- basicPage(
h2("The mtcars data"),
column(5,offset = 5,actionButton("CR1_S1", "Button")),
dataTableOutput("mytable1")
)
server <- function(input, output) {
output$mytable1 <- DT::renderDataTable({
DT::datatable(iris)
})
}
shinyApp(ui, server)
You can put the button inside the datatable in this way:
ui <- basicPage(
h2("The mtcars data"),
actionButton("CR1_S1", "Button"),
DTOutput("mytable1")
)
server <- function(input, output) {
output$mytable1 <- renderDT({
datatable(iris, callback = JS("$('div.button').append($('#CR1_S1'));"),
options = list(
dom = '<"row"<"col-sm-4"l><"col-sm-4 text-center"<"button">><"col-sm-4"f>>tip'
))
})
}
shinyApp(ui, server)

How to build simple google chart in Shiny

I am new to shiny and the googleVis packages, and I am trying to construct to create a simple, bare bones gvisMotionChart in Shiny. I have been able to create the gvisMotionChart in a separate file, but when I try to run the Shiny app, it only displays the side bar panel and does not generate the animated chart.
ui.R
library(shiny)
library(googleVis)
shinyUI(fluidPage(
titlePanel("Google Motion Chart"),
sidebarLayout(
sidebarPanel("Inputs go Here"),
mainPanel(
htmlOutput("view")
)
)
))
server.R
library(shiny)
library(googleVis)
shinyServer(function(input, output) {
output$view <- renderGvis({
gvisMotionChart(Fruits,
idvar="Fruit",
timevar="Year")
})
})
One needs to enter:
shinyServer(function(input, output) { datasetInput <-
reactive({gvisMotionChart(Fruits, idvar="Fruit", timevar="Year") })
output$coolplot <- renderGvis ({ datasetInput() }) })

including two tabs in tabsetpanel breaks shiny

ui.r
shinyUI(
fluidPage(
titlePanel("the title"),
mainPanel(
tabsetPanel(tabPanel("Raw Data",verbatimTextOutput("theText")),
tabPanel("Raw Data2",verbatimTextOutput("theText"))
)
)
)
)
server.r
library("shiny")
library("dplyr")
shinyServer(
function(input, output,session) {
print("do it")
output$theText <- renderText({
return("please work")})
}
)
If I remove one tabPanel it works, and "do it" is printed in the console and the title and "please work" is printed in the UI. Otherwise, with both, the UI with two tabs shows up and nothing is printed or displayed within the tabs, though an empty grey box does show up.
Using RStudio 0.99.332, R 3.1.2, shiny 0.11.1
In rshiny one output can go only to one place, which means that you have to create new output for other tabPanel.
library(shiny)
server <- function(input, output, session) {
print("do it")
output$theText <- renderText({
return("please work")})
output$theText2 <- renderText({
return("please work")})
}
ui <- fluidPage(
titlePanel("the title"),
mainPanel(
tabsetPanel(tabPanel("Raw Data",verbatimTextOutput("theText")),
tabPanel("Raw Data2",verbatimTextOutput("theText2"))
)
)
)
shinyApp(ui = ui, server = server)

Resources