renderPlot outputs plot in View, not browser - r

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)

Related

Cannot render flow chart in R shiny

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)

ggplot not showing - area is blank

I am relatively new to ggplot2 and I have created a plot based on a csv file.
The problem I am having is that the plot is blank:
Nothing shows expect the title and I am not sure why!
As you can see the data is fine within RStudio:
My csv file is in the same directory as my app.R file:
My working directory is the same folder:
So why is ggplot2 failing to pick up the data held within the csv file?
Here is my code:
library(shiny)
library(ggplot2)
ui <- (fluidPage(
titlePanel("Pig Breeding")
)
)
mainPanel(
plotOutput(outputId = "scatterplot")
)
server <- (function(input, output){
output$scatterplot <- renderPlot({
pig_plot <- ggplot(read.csv("pigs_data.csv"),
aes_string(x = "species", y = "sow_count") +
geom_point())
})
})
shinyApp(ui, server)
the below code works with a test data called iris. Your mistake lies in your
ui <- (fluidPage(
titlePanel("Pig Breeding")
)
)
mainPanel(
plotOutput(outputId = "scatterplot")
)
ui code. You have left your mainPanel out of the fluidpage parenthesis. Thus, it does not read the plotOutput.
Example
library(shiny)
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("Iris data"),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
# Define server logic
server <- function(input, output) {
output$distPlot <- renderPlot({
ggplot(iris, aes(x=Sepal.Width, y=Petal.Width)) + geom_point()
})
}
# Run the application
shinyApp(ui = ui, server = server)
The code below should work for your question.
library(shiny)
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("Pig Breeding"),
# Show a plot of the generated distribution
mainPanel(
plotOutput("scatterplot")
)
)
# Define server logic
server <- function(input, output) {
output$scatterplot <- renderPlot({
ggplot(read.csv("pigs_data.csv"),
aes(x = "species", y = "sow_count")) + geom_point()
})
}
# Run the application
shinyApp(ui = ui, server = server)

How to use tmap with shiny

I am having issues getting a map using tmap to load in shiny. When I run the shiny code, the input sections show up, but not the output. The code doesn't crash, but it also never finishes running. My goal is to be able to have an interactive map using tmap and leaflet, which has been able to run outside of shiny.
library(tmap) # and maybe also: library(tmaptools)
library(shiny)
ui <- fluidPage(
titlePanel("Europe"),
mainPanel(
plotOutput(outputId = "europe")))
server <- function(input, output) {
output$europe <- renderPlot({
qtm(Europe)})}
shinyApp(ui, server)
All works for me:
library(shiny)
library(tmap)
data("Europe")
ui <- fluidPage(
titlePanel("Europe"),
mainPanel(
plotOutput(outputId = "europe")))
server <- function(input, output) {
output$europe <- renderPlot({
qtm(Europe)
})
}
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)

I am building shiny dashboard where I need to render table dynamically..my code below

I am trying to build shiny dashboard application.
Within the application, I need to render a table dynamically.
When I load the application, I am not receiving the tabular output.
I have split the code into three files: global.R, ui.R, and server.R
global.R
my_data <- head(mtcars)
ui.R
tabItem(tabName = "impRels",
fluidRow(
box(DT::dataTableOutput("table1"))
)
)
server.R
output$table1 <- DT::renderDataTable({
datatable(my_data)
})
Simplified, as a start. You might want to work on your UI, though.
library(shiny)
library(DT)
my_data <- head(mtcars)
ui <- shinyUI(
fluidPage(
fluidRow( dataTableOutput("table1") )
)
)
server <- shinyServer(function(input, output, session){
output$table1 <- renderDataTable({ datatable(my_data) })
})
shinyApp(ui=ui, server=server)

Resources