The given code creates a simple scatterPlot. I wish to click on the plot and move it in any direction that I want to, basically the span functionality. Attached the snapshot for references.Please help and thanks.
## app.R ##
library(shiny)
library(shinydashboard)
library(bupaR)
library(edeaR)
library(eventdataR)
library(processmapR)
library(processmonitR)
library(xesreadR)
library(lubridate)
library(dplyr)
library(knitr)
library(XML)
library(xml2)
library(data.table)
library(ggplot2)
library(ggthemes)
library(glue)
library(tibble)
library(miniUI)
library(tidyr)
library(shinyTime)
library(petrinetR)
library(magrittr)
library(shinyWidgets)
library(DiagrammeR)
ui <- dashboardPage(
dashboardHeader(title = "Zoom and Reset Dashboard",titleWidth = 290),
dashboardSidebar(
width = 0
),
dashboardBody(
# Creation of tabs and tabsetPanel
tabsetPanel(type = "tab",
tabPanel("Resource Dashboard",
fluidRow(column(10,
grVizOutput("res_freq_plot")))),
id= "tabselected"
)
))
server <- function(input, output)
{
output$res_freq_plot <- renderDiagrammeR(
{
patients %>% process_map()
}
)
}
shinyApp(ui, server)
You can use plotly
## app.R ##
library(shiny)
library(plotly)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Zoom and Reset Dashboard",titleWidth = 290),
dashboardSidebar(
width = 0
),
dashboardBody(
# Creation of tabs and tabsetPanel
tabsetPanel(type = "tab",
tabPanel("Resource Dashboard",
fluidRow(column(10,
plotlyOutput("res_freq_plot")))),
id= "tabselected"
)
))
server <- function(input, output)
{
output$res_freq_plot <- renderPlotly(
{
plot_ly(iris, x= iris$Petal.Length, y = iris$Sepal.Length)
}
)
}
shinyApp(ui, server)
Related
In the DT::datatable() of my shiny app below I have found how to add "thousands" mark )(.) in my table but I want to get rid of the decimals numbers.
library(shiny)
library(shinydashboard)
library(DT)
## app.R ##
library(shiny)
library(shinydashboard)
library(DT)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
),
dashboardBody(
dataTableOutput("table")
)
)
server <- function(input, output) {
iris<-iris[,1:4]*100000
output$table <- renderDataTable({
datatable(iris) %>%
formatCurrency(columns = c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width"), currency = "", interval = 3, mark = ".") %>%
formatStyle(
columns = c("Sepal.Length")
) })
}
shinyApp(ui, server)
Just add digits=0 to the formatCurrency().
In shiny the ggplotly visual looks like:
If I create a screenshot with shinyscreenshot it appears with a colorless legend:
Is there any way to solve this issue?
Update 12:04
It seems that this issues only appears with colorbars. With factorized groups the legend works:
Unfortunately, in real world data I need the colorbar as its a range between 0.0001 and 100%.
MWE
library(shiny)
library(shinydashboard)
library(shinyscreenshot)
library(data.table)
library(DT)
library(bslib)
library(plotly)
################################################################################
################################ S E R V E R ###################################
################################################################################
server = shinyServer(function(input,output){
output$histogram = renderPlotly(
ggplotly(ggplot(mtcars, aes(x=disp, y=hp, color=gear)) + geom_point())
)
output$active_cases = DT::renderDataTable(
mtcars)
######################### SCREENSHOT REACTIVE FUNCTION #########################
observeEvent(input$go,{
screenshot(id = "to_plot") # plot only ID "to_plot"
})
######################### SCREENSHOT REACTIVE FUNCTION #########################
})
################################################################################
#################################### U I #######################################
################################################################################
ui = shinyUI(
dashboardPage(
dashboardHeader(
title="just a test"
),
dashboardSidebar(
sidebarMenu(id="tabs",
menuItem("Tab1", tabName="active_cases", icon = icon("magnifying-glass-location"))
)
),
dashboardBody(
tabItems(
tabItem(tabName="active_cases", shiny::h2("Active Cases"),
fluidRow(actionButton("go", "go")),
fluidRow(
box(title="Table", status="primary", solidHeader=TRUE, div(DT::dataTableOutput("active_cases")))
),
div(id="to_plot",
fluidRow(
box(title="Visual1", status="primary", solidHeader=TRUE, plotlyOutput("histogram"))
)
)
)))))
################################################################################
################################### R U N ######################################
################################################################################
shinyApp(ui, server)
You could use library(capture) instead of library(shinyscreenshot):
# remotes::install_github("dreamRs/capture")
library(shiny)
library(shinydashboard)
library(capture)
library(data.table)
library(DT)
library(bslib)
library(plotly)
################################################################################
################################ S E R V E R ###################################
################################################################################
server = shinyServer(function(input,output){
output$histogram = renderPlotly(
ggplotly(ggplot(mtcars, aes(x=disp, y=hp, color=gear)) + geom_point())
)
output$active_cases = DT::renderDataTable(
mtcars)
})
################################################################################
#################################### U I #######################################
################################################################################
ui = shinyUI(
dashboardPage(
dashboardHeader(
title="just a test"
),
dashboardSidebar(
sidebarMenu(id="tabs",
menuItem("Tab1", tabName="active_cases", icon = icon("magnifying-glass-location"))
)
),
dashboardBody(
tabItems(
tabItem(tabName="active_cases", shiny::h2("Active Cases"),
fluidRow(
capture::capture(
selector = "#to_plot",
filename = "capture_plotly.png",
icon("camera"), "Capture plotly graph",
options=list(backgroundColor = "white")
)
),
fluidRow(
box(title="Table", status="primary", solidHeader=TRUE, div(DT::dataTableOutput("active_cases")))
),
div(id="to_plot",
fluidRow(
box(title="Visual1", status="primary", solidHeader=TRUE, plotlyOutput("histogram"))
)
)
)))))
################################################################################
################################### R U N ######################################
################################################################################
shinyApp(ui, server)
In the shiny app below Im trying to use shinyJS() to hide and display text but I get:
Error: shinyjs: could not find the Shiny session object. This usually happens when a shinyjs function is called from a context that wasn't set up by a Shiny session.
Do not bother that dataset does not exist its just an example
## app.R ##
library(shiny)
library(shinydashboard)
library(dplyr)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(title = "Biodiversity"),
dashboardSidebar(
actionButton("action","Submit")
),
dashboardBody(
useShinyjs(),
show(
div(id='text_div',
verbatimTextOutput("text")
)
),
uiOutput("help_text"),
plotlyOutput("plot")
)
)
server <- function(input, output) {
output$help_text <- renderUI({
HTML("<b>Click 'Show plot' to show the plot.</b>")
})
react<-eventReactive(input$action,{
hide("help_text")
omited <-subset(omited, omited$scientificName %in% isolate(input$sci)&omited$verbatimScientificName %in% isolate(input$ver))
})
}
shinyApp(ui = ui, server = server)
You can't use show() in the ui, these functions are used in the server. Remove that and it works. Sample:
## app.R ##
library(shiny)
library(shinydashboard)
library(dplyr)
library(shinyjs)
library(plotly)
ui <- dashboardPage(
dashboardHeader(title = "Biodiversity"),
dashboardSidebar(
actionButton("action","Submit")
),
dashboardBody(
useShinyjs(),
div(id='text_div',
verbatimTextOutput("text")
)
,
uiOutput("help_text"),
plotOutput("plot")
)
)
server <- function(input, output) {
output$help_text <- renderUI({
HTML("<b>Click 'Show plot' to show the plot.</b>")
})
observeEvent(input$action,{
hide("help_text")
output$plot <- renderPlot({
plot(1)
})
})}
shinyApp(ui = ui, server = server)
Output:
I want to change the color of legends in piechart.
Here is the code:
library(ECharts2shiny)
library(shiny)
dat5 <- c(rep("Female", 3376), rep("Male", 2180))
ui <- shinyUI(
dashboardPage(dashboardHeader(title = "PSM"),
dashboardBody(
mainPanel(
tabsetPanel(
tabPanel(
loadEChartsLibrary(), tags$div(id="test5",
style="width:60%;height:300px;"),
deliverChart(div_id = "test5"))
server <- shinyServer(function(input,output){
renderPieChart(div_id = "test5", data = dat5 ) })
Can anybody help me how to change the legends color?
hope it helps:
library(shiny)
library(shinydashboard)
dat5 <- c(rep("Female", 3376), rep("Male", 2180))
app <- shinyApp(
ui <- shinyUI(
dashboardPage(dashboardHeader(title = "PSM"),
dashboardSidebar(),
dashboardBody(
mainPanel(
tabsetPanel(
tabPanel(tags$div(id="test5",
style="width:60%;height:300px;"),
plotOutput("pie_chart"))
))))
),
server <- shinyServer(function(input,output){
output$pie_chart <- renderPlot({
df <- table(dat5)
cols <- rainbow(length(df))
pie(df, col = cols)
})
})
)
runApp(app)
The script below when executed creates a process_map() with a select input. Upon selecting a resource like "r1","r2" etc. we get the corresponding process map. However I want to dynamically pass an input from the selectInput bar and update the process map within R shiny page Snapshot for your reference. Please help.
## app.R ##
install.packages("bupaR")
install.packages("edeaR")
install.packages("eventdataR")
install.packages("processmapR")
install.packages("processmonitR")
install.packages("xesreadR")
install.packages("petrinetR")
install.packages("shiny")
install.packages("shinydashboard")
library(shiny)
library(shinydashboard)
library(bupaR)
library(edeaR)
library(eventdataR)
library(processmapR)
library(processmonitR)
library(xesreadR)
library(petrinetR)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectInput("resources","Select the resource", c("r1","r2","r3","r4","r5"),
selected = "r1",selectize = T)
),
dashboardBody(
filter_resource(patients,resources = c("r1","r2","r4"), reverse = F) %>%
process_map()
))
server <- function(input, output) {
}
shinyApp(ui, server)
You could do
library(shiny)
library(shinydashboard)
library(bupaR)
library(edeaR)
library(eventdataR)
library(processmapR)
library(processmonitR)
library(xesreadR)
library(petrinetR)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectInput("resources","Select the resource", c("r1","r2","r3","r4","r5"),selected = "r1",selectize = T)
),
dashboardBody(
uiOutput("ui")
))
server <- function(input, output) {
output$ui <- renderUI({
r <- input$resources
tagList(filter_resource(patients,resources = r, reverse = F) %>% process_map())
})
}
shinyApp(ui, server)